feat(download_lt/safe_zip): new secure way to extract ZIPs#165
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR hardens the LanguageTool ZIP download/extract flow against ZIP slip, symlink, zip-bomb, name-collision, and oversized-download attacks by introducing a dedicated SafeZipExtractor and adding HTTP download size validation in download_lt.py.
Changes:
- Adds
language_tool_python/safe_zip.pywithSafeZipLimitsandSafeZipExtractor(path normalization, member-type checks, per-member and total size/ratio limits, two-stage extract via private temp dir). - In
download_lt.py: validatesContent-Length, enforcesMAX_DOWNLOAD_BYTESwhile streaming, switches all extraction sites (unzip_file, release/snapshotdownload()) to the safe extractor, and removes the snapshot rename fallback. - Adds extensive new tests in
tests/test_safe_zip.pyandtests/test_download.pycovering unsafe member names, symlinks, conflicts, ratio/size limits, and download size enforcement.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| language_tool_python/safe_zip.py | New module implementing safe ZIP validation and extraction. |
| language_tool_python/download_lt.py | Wires the safe extractor into all unzip paths and adds streaming download size limits; removes snapshot directory rename. |
| tests/test_safe_zip.py | Comprehensive tests for the new safe extractor. |
| tests/test_download.py | New tests verifying download size and Content-Length validation. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
1737ac1 to
fd2a0fa
Compare
fd2a0fa to
0901fe3
Compare
0901fe3 to
c5c40cb
Compare
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.
feat(download_lt/safe_zip): new secure way to extract ZIPs
Why the pull request was made
This feature allows for reducing the risk of extracting unverified ZIPs files (non-verified hashes, as for snapshots).
Summary of changes
safe_zip.pycontaining a classSafeZipExtractorthat allows to safely extract ZIPsdownload_lt.pyScreenshots (if appropriate):
Not applicable.
How has this been tested?
Applied local tests (including new ones), tested downloading of multiple versions.
Resources
Not applicable.
Types of changes
Checklist