-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Prevent shell injection in load_djpeg #731
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
|
I see 6 places where os.system is used in the package (+ 1 in setup that's not vulnerable) From a quick check of those, ImageShow has already had this done to it, and the other ones appear to have the same issue. We should clean them all up, either this way or by changing them to use the subprocess interface that doesn't use a shell for redirection. If we do continue quoting, we should probably pull the quote function import logic into _util.py. |
|
Each of these six should have a test case, and the vulnerable ones should fail before the fixes. The tests should be in their own test_shell_injection.py (or something) file. |
|
We really should change all I have a few questions before I write tests:
Most of the functions where |
|
The functions don't need to be registered to be called. That's part of the danger of them. They're historical baggage. I've wanted to simply get rid of them for a while -- the chances that someone has djpeg but not libjpeg is pretty minimal. The use case for the gifs is a little better, but still not great. |
|
Should I merge this, or wait? I would rather err on the side of security over backwards compatibility, for whatever it's worth. |
|
Wait. It's been this way for 10 years, another day isn't going to hurt. We'll get a solution prior to 2.5. |
|
@wiredfool Well if you are targeting 2.5 for this then you literally only have another few days 😄 |
|
Probably need to add |
|
Any idea how to perform a cross platform check to see if an executable is in the path? Perhaps running, for example, "djpeg -h" before the test and skipping if an OSError is thrown (or catching the OSError thrown in load_djpeg)? It seems a bit of a hack, but a proper "which" function in Python would be a bit overkill (https://code.google.com/p/which/). |
|
We're doing something like that in EpsImagePlugin.py: https://github.com/python-pillow/Pillow/blob/master/PIL/EpsImagePlugin.py#L39 , where we're splitting out the windows check from the unix check. In that case, we're checking the version of ghostscript, but we could execute a shell just for the which command as well. |
|
We're already implicitly using a shell in os.system. It's difference between |
|
Right, |
The only places left that use os.system are in ImageShow and setup.py
|
Rebased my commits. Let me know if there's anything else I need to do before a merge. |
|
See #748. |
Although
JpegImageFile.load_djpegisn't documented or used anywhere, it is public. This fix prevents shell injection in filenames that contain single quotes.