-
-
Notifications
You must be signed in to change notification settings - Fork 31.1k
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
[security] CVE-2019-9674: Zip Bomb vulnerability #80441
Comments
Dear Python Community, We’ve found a vulnerability in cpython Lib and already received a cve number (CVE-2019-9674) We also have a patch for this vulnerability, please tell us what to do next. JUN-WEI SONG |
Dear community, I am one of the discoverer of this vulnerability, please tell us what to do next :D Kunyu Chen |
You can find the process to report security vulnerabilities at https://www.python.org/news/security/ . Please email the details to security@python.org and who will analyze the report before public disclosure. |
Thank you Karthikeyan Singaravelan. Kunyu Chen |
Issue bpo-36462 contains more information. The reporter claims that the zipfile module is inherent insecure because it does not provide any heuristics to make zipbomb attacks harder. I'm -1 to implement such a heuristic. The zipfile module is a low level module and should not limit extraction by defaykt. Instead we should improve documentation and maybe implement some method that simplifies detection of zipbomb attacks. I'm thinking about a method that returns total count of files, total compressed size and total uncompressed size. |
All these are simple one-liners: len(zf.infolist())
sum(zi.compress_size for zi in zf.infolist())
sum(zi.file_size for zi in zf.infolist()) |
Thank you python community, these two issues are indeed the same problem. I also think that it is good to make a related document to reduce such problems. |
1 similar comment
Thank you python community, these two issues are indeed the same problem. I also think that it is good to make a related document to reduce such problems. |
Thank you for the responses. I agree with Christian Heimes. It's indeed better to improve the documentation rather than directly implement the heuristic. |
Hello Python community, With Christian Heimes’ suggestion, we manipulate appropriate warning to inform users that they may encounter zip bomb issues when using the zipfile module. The warning we would like to add in the zipfile documentation is shown below : https://github.com/python/cpython/blob/3.7/Doc/library/zipfile.rst .. warning::
You can protect your system by limiting system resources, limiting compression ratio (zip bombs are usually quite high), and checking for nested zip files. We are also pleasure to provide a patch to enhance the zipfile module to provide basic information. In zipfile.py https://github.com/python/cpython/blob/master/Lib/zipfile.py Inside the ZipFile class : def filecount(self):
"""Return total count of files in the archive."""
return len(self.filelist)
def total_compressed_size(self):
"""Return total compressed size in the archive."""
return sum([data.compress_size for data in self.filelist])
def total_uncompressed_size(self):
"""Return total uncompressed size in the archive."""
return sum([data.file_size for data in self.filelist]) |
I am against such trivial methods in ZipFile. Its interface is already complicate. The advantage of Python is that you do not need tons of methods for every possible query -- you can just combine few Python features into a one-line expression. As for the documentation change, it could be useful to add more general note about possible pitfalls. What happen when interrupt extracting or adding to the archive, what happen when extract into existing tree or overwrite an existing file, what happen when the file system does not support some file names, what happen when extract to case-insensitive file system, what happen when extract encrypted file with wrong password, etc. We do not have to tell the user what he should not do, just to warn about the possible consequences. |
Hello Python community, I’m curious why the patch or pitfall prevention in ZipFile Victor Kung |
The suggested approach is merely a heuristic that reduces the impact of a zipbomb. An attacker can circumvent the heuristic. In best case scenario, the approach just increases the cost factor for a successful DoS. For example an attacker may have to upload 10 larger zip files instead of one smaller zip file to fill up the disk space of a server. The correct approach is to always verify all data from untrusted sources. It's the 101 of application security. |
I see. @christian Heimes Thank you for the response. |
Thank you very much for your reply. Based on discussions above, consensuses are improving the zipfile documentation. And we (JUN-WEI SONG & KunYu Chen) would like to work on this. With opinions of Serhiy Storchaka, Christian Heimes and the ideas we have, possible pitfalls are listed below.
Please let us know if anything’s missing. |
Dear friends, We moved a little bit forward to improve the writing. :) |
I marked bpo-39341 as a duplicate of this issue: "[security] zipfile: ZIP Bomb vulnerability, don't check announced uncompressed size". |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: