Uh oh!
There was an error while loading. Please reload this page.
gh-68966: Fix CVE-2015-20107 in mailcap - #91542
Conversation
gpshead
left a comment
There was a problem hiding this comment.
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.
| 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.
JelleZijlstra
commented
Apr 15, 2022
This is still vulnerable with a sufficiently buggy (had to set plist to work around the bug in #91542 (comment)) |
JelleZijlstra
commented
Apr 15, 2022
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. |
vstinner
commented
Apr 20, 2022
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. |
encukou
commented
Apr 20, 2022
Maybe not a temporary file, but use an environment variable and pass |
gpshead
commented
Apr 20, 2022
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"? |
vstinner
commented
Apr 25, 2022
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. |
hugovk
commented
Apr 26, 2022
Note that mailcap will be deprecated in Python 3.11 and removed in 3.13: |
encukou
commented
Apr 27, 2022
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 |
arhadthedev
commented
Apr 28, 2022
Closing in favor of #91993. |
Fixes#68966. See #68966 (comment) for a detailed report.
Likely neeeds a backport up to 3.9.