feat: add configurable safety limits to ZipConverter#1666
Open
VANDRANKI wants to merge 1 commit intomicrosoft:mainfrom
Open
feat: add configurable safety limits to ZipConverter#1666VANDRANKI wants to merge 1 commit intomicrosoft:mainfrom
VANDRANKI wants to merge 1 commit intomicrosoft:mainfrom
Conversation
The previous ZipConverter had no limits on file count, per-file size, or total uncompressed size, making it vulnerable to zip bomb extraction. It also had no protection against zip slip path traversal attacks. Changes: - Add max_file_count constructor parameter (default 100): stops processing when the limit is reached and appends a notice - Add max_file_size constructor parameter (default 50 MB): skips individual files that exceed the limit with a per-file notice - Add max_total_size constructor parameter (default 200 MB): stops processing when cumulative uncompressed bytes would exceed the limit - Guard against zip slip: skip entries whose name starts with '/' or contains '..' path components (handles both POSIX and Windows paths) - Iterate over ZipInfo objects instead of namelist() to read file_size before extracting - Skip directory entries (names ending with '/') - Add 10 tests covering all limit types, zip slip, and accepts() Closes: microsoft#1661
Author
|
@microsoft-github-policy-service agree |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The current
ZipConverterhas no limits on how many files it processes or how much data it extracts. A maliciously crafted zip file (zip bomb) can compress gigabytes of data into a small archive, causing OOM or denial of service when converted. There is also no protection against zip slip path traversal attacks.Changes
converters/_zip_converter.py:max_file_count(default 100): stops processing when limit is reached, appends a noticemax_file_size(default 50 MB): skips individual files that exceed the limit with a per-file noticemax_total_size(default 200 MB): stops processing when cumulative uncompressed bytes would exceed the budget/or contains..path components (cross-platform - handles both POSIX and Windows absolute paths)ZipInfoobjects instead ofnamelist()to readfile_sizebefore extracting/)tests/test_zip_converter.py(new file): 10 tests covering all limit types, zip slip protection, andaccepts().Usage
Tests
Closes #1661