-
-
Notifications
You must be signed in to change notification settings - Fork 31.7k
gh-68966: Fix CVE-2015-20107 in mailcap #91542
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it plausible to create a regression test for this?
@@ -170,7 +172,7 @@ def findmatch(caps, MIMEtype, key='view', filename="/dev/null", plist=[]): | |||
for e in entries: | |||
if 'test' in e: | |||
test = subst(e['test'], filename, plist) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
test = subst(e['test'], filename, plist) | |
test = subst(e['test'], MIMEtype, filename, plist) |
Don't know that we should fix this, but this is actually broken if test
has a %s
in it.
This is still vulnerable with a sufficiently buggy
(had to set plist to work around the bug in #91542 (comment)) |
Also, this approach will break some legitimate uses. On my Ubuntu system, mailcap has a lot of entries like Maybe mailcap is just vulnerable by design. We can just put a big red banner in the docs and a warning on import, and be done with it when we remove the module in 3.13. |
I confirm. For me, it's the responsibility of the caller (users of the mailcap API) to sanitize arguments. Maybe the Python mailcap module documentation can suggest to use shlex.quote() Does it work to pass I also read somewhere that it's possible to use a temporary file to have a safe filename. But I don't know how to do that. |
Maybe not a temporary file, but use an environment variable and pass |
Certainly a documentation update is a good idea (make a separate PR for that - we should get that in if nothing else). If we cannot actually fix all possible problems with this because of mailcap's fundamental design is it worth even a partial "fix"? |
I'm talking about this:
There is already a way to avoid mailcap vulnerabilities without fixing the code. It can be the responsibility of the caller to handle security. Python stdlib has many very dangerous modules like os, shutil, ctypes or pickle. The pickle module clearly documents that it must not used to deserialize untrusted data. mailcap is not an exception here. |
Note that mailcap will be deprecated in Python 3.11 and removed in 3.13: |
Sorry for the misguided comment above.
No, because we can't be sure of the context. This was mentioned in the issue in 2015: if the mailcap line already includes quotes, as in |
Closing in favor of #91993. |
Fixes #68966. See #68966 (comment) for a detailed report.
Likely neeeds a backport up to 3.9.