Skip to content
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

CVE-2019-9674 : zip bomb vulnerability in Lib/zipfile.py #80643

Closed
krnick mannequin opened this issue Mar 28, 2019 · 7 comments
Closed

CVE-2019-9674 : zip bomb vulnerability in Lib/zipfile.py #80643

krnick mannequin opened this issue Mar 28, 2019 · 7 comments
Labels
3.7 (EOL) end of life 3.8 only security fixes stdlib Python modules in the Lib dir type-security A security issue

Comments

@krnick
Copy link
Mannequin

krnick mannequin commented Mar 28, 2019

BPO 36462
Nosy @Yhg1s, @brettcannon, @serhiy-storchaka, @tirkarthi, @krnick
Superseder
  • bpo-36260: [security] CVE-2019-9674: Zip Bomb vulnerability
  • 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:

    assignee = None
    closed_at = <Date 2019-03-28.16:43:08.889>
    created_at = <Date 2019-03-28.15:46:10.987>
    labels = ['type-security', '3.8', '3.7', 'library']
    title = 'CVE-2019-9674 : zip bomb vulnerability in Lib/zipfile.py'
    updated_at = <Date 2019-03-29.00:03:09.020>
    user = 'https://github.com/krnick'

    bugs.python.org fields:

    activity = <Date 2019-03-29.00:03:09.020>
    actor = 'krnick'
    assignee = 'none'
    closed = True
    closed_date = <Date 2019-03-28.16:43:08.889>
    closer = 'brett.cannon'
    components = ['Library (Lib)']
    creation = <Date 2019-03-28.15:46:10.987>
    creator = 'krnick'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 36462
    keywords = []
    message_count = 7.0
    messages = ['339053', '339055', '339056', '339058', '339060', '339063', '339085']
    nosy_count = 5.0
    nosy_names = ['twouters', 'brett.cannon', 'serhiy.storchaka', 'xtreak', 'krnick']
    pr_nums = []
    priority = 'normal'
    resolution = 'duplicate'
    stage = 'resolved'
    status = 'closed'
    superseder = '36260'
    type = 'security'
    url = 'https://bugs.python.org/issue36462'
    versions = ['Python 3.5', 'Python 3.6', 'Python 3.7', 'Python 3.8']

    @krnick
    Copy link
    Mannequin Author

    krnick mannequin commented Mar 28, 2019

    Dear Python Community,

    we found a python module vulnerability during these days and we got a CVE number, CVE-2019-9674 after reported it to cve.mitre.org.

    https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2019-9674

    The reserved information of CVE-2019-9674 is shown below:

       [Description]
    
           [Lib/zipfile.py](https://github.com/python/cpython/blob/main/Lib/zipfile.py) in Python through 3.7.2 allows remote 
           attackers to cause a denial of service (resource consumption) 
           via a ZIP bomb.
    
    
           [Additional Information]
    
           The python zipfile library version 3.2, 3.3, 3.4, 3.5, 3.6, 
           3.7, 3.8. Allow attackers to cause a denial of service (disk 
           volume exhaustion) via a ZIP bomb.
    
    
           We have found python standard library zipfile doesn't have 
           ZIP bomb detection and protection. If the user uses zipfile 
           library to unzip a ZIP bomb file, this might cause a denial 
           of service of the localhost.
    
    
          [VulnerabilityType Other]
    
          Denial-of-Service
    

    Our proposed solutions:

    1.The compression ratio:
    
    Compression ratio = Uncompressed file size / Compressed file size
    
    Since ZIP bomb file has a higher compression ratio (1028) than 
    normal ZIP file (1 to 3). Therefore, we calculate the compression 
    ratio and set a threshold for the detection.
    
    2.Nested zip file
    
    There is a high chance that it is zip bomb if it is a nested zip 
    file. 
    
    3.By limiting resources such as CPU, memory, disk usage.
    

    Unsolved issue

    However, we have not yet determined the compression ratio. We 
    temporarily set the compression ratio to 10, and if it exceeds, it 
    may be a ZIP bomb.
    
    It is likely that detection may misjudge nested compressed files. 
    For example, under normal circumstances, compressed files are 
    included in the zip file.
    

    Our solution code:

    """For ratio"""

    def _exam_ratio(self, threshold=10):
        """If the ratio exceeds threshold, it may be a ZIP Bomb."""
        sum_file_size = sum([data.file_size for data in self.filelist])
        sum_compress_size = sum([data.compress_size for data in self.filelist])
        ratio = sum_file_size / sum_compress_size
        if (ratio > threshold):
            raise BadZipFile("Zip Bomb Detected")

    """For Nested zip file"""

    if(members.filename.endswith(".zip")):
    raise BadZipFile("Nested Zip File Detected")

    Thanks!

    @krnick krnick mannequin added 3.7 (EOL) end of life 3.8 only security fixes stdlib Python modules in the Lib dir type-security A security issue labels Mar 28, 2019
    @serhiy-storchaka
    Copy link
    Member

    I do not think that the library should limit the compression ratio. Large compression ratio is legit. For example, compressed file of size 1 GiB consisting of zeros has the compress ratio 1030 (and I suppose it is even larger if use bzip2 or lzma compressions).

    If this is a problem for your program, your program should make a decision what ZIP files should be rejected.

    I suggest to close this issue as "not a bug".

    @tirkarthi
    Copy link
    Member

    Going by CVE number and report is this a duplicate of bpo-36260 ?

    @brettcannon
    Copy link
    Member

    Closing as a duplicate of bpo-36260.

    @tirkarthi
    Copy link
    Member

    I would request closing the other one as duplicate and opening this since this contains the actual report or perhaps the report could be copied to bpo-36260. Since Serhiy suggested closing this as not a bug I will leave it to him on resolution of the other issue too.

    @brettcannon
    Copy link
    Member

    You can also leave a comment in the other issue saying there's more details
    in the closed duplicate.

    On Thu, Mar 28, 2019 at 9:54 AM Karthikeyan Singaravelan <
    report@bugs.python.org> wrote:

    Karthikeyan Singaravelan <tir.karthi@gmail.com> added the comment:

    I would request closing the other one as duplicate and opening this since
    this contains the actual report or perhaps the report could be copied to
    bpo-36260. Since Serhiy suggested closing this as not a bug I will leave
    it to him on resolution of the other issue too.

    ----------


    Python tracker <report@bugs.python.org>
    <https://bugs.python.org/issue36462\>


    @krnick
    Copy link
    Mannequin Author

    krnick mannequin commented Mar 29, 2019

    Thanks to the python community, both of these issues are the same.

    I also think it's a good thing to make related documentation to reduce this type of problem rather than implementing it on a low-level zipfile module. Perhaps we can customize such a requirement through a pip package.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.7 (EOL) end of life 3.8 only security fixes stdlib Python modules in the Lib dir type-security A security issue
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants