Skip to content

feat(download_lt/safe_zip): new secure way to extract ZIPs#165

Merged
mdevolde merged 1 commit into
jxmorris12:masterfrom
mdevolde:feature/safe_install
May 14, 2026
Merged

feat(download_lt/safe_zip): new secure way to extract ZIPs#165
mdevolde merged 1 commit into
jxmorris12:masterfrom
mdevolde:feature/safe_install

Conversation

@mdevolde
Copy link
Copy Markdown
Collaborator

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

  • New module safe_zip.py containing a class SafeZipExtractor that allows to safely extract ZIPs
  • New ZIP size verification in download_lt.py
  • New tests linked to these changes

Screenshots (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

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update (changes to documentation only)
  • Refactor / code style update (non-breaking change that improves code structure or readability)
  • Tests / CI improvement (adding or updating tests or CI configuration only)
  • Other (please describe):

Checklist

  • Followed the project's contributing guidelines.
  • Updated any relevant tests.
  • Updated any relevant documentation.
  • Added comments to your code where necessary.
  • Formatted your code, run the linters, checked types and tests.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.py with SafeZipLimits and SafeZipExtractor (path normalization, member-type checks, per-member and total size/ratio limits, two-stage extract via private temp dir).
  • In download_lt.py: validates Content-Length, enforces MAX_DOWNLOAD_BYTES while streaming, switches all extraction sites (unzip_file, release/snapshot download()) to the safe extractor, and removes the snapshot rename fallback.
  • Adds extensive new tests in tests/test_safe_zip.py and tests/test_download.py covering 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.

Comment thread language_tool_python/download_lt.py
Comment thread language_tool_python/safe_zip.py Outdated
@mdevolde mdevolde force-pushed the feature/safe_install branch 2 times, most recently from 1737ac1 to fd2a0fa Compare May 14, 2026 14:50
@mdevolde mdevolde requested a review from Copilot May 14, 2026 14:50
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

Comment thread tests/test_safe_zip.py
Comment thread language_tool_python/download_lt.py
Comment thread language_tool_python/download_lt.py Outdated
@mdevolde mdevolde force-pushed the feature/safe_install branch from fd2a0fa to 0901fe3 Compare May 14, 2026 15:12
@mdevolde mdevolde force-pushed the feature/safe_install branch from 0901fe3 to c5c40cb Compare May 14, 2026 16:00
@mdevolde mdevolde merged commit 6d15762 into jxmorris12:master May 14, 2026
8 checks passed
@mdevolde mdevolde deleted the feature/safe_install branch May 14, 2026 16:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants