Fix Zip Slip vulnerability in archive extraction #296
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.
Summary
Fixes the Zip Slip vulnerability (arbitrary file write during archive extraction) in the
Expand
class by improving path validation to prevent directory traversal attacks.Resolves: https://github.com/codehaus-plexus/plexus-utils/security/code-scanning/1
Problem
The Zip Slip vulnerability is a form of directory traversal attack that allows a malicious zip file to write files outside the intended extraction directory. The original validation in
Expand.extractFile()
was insufficient:This check had two critical flaws:
/tmp/extract-evil/malicious.txt
when extracting to/tmp/extract
because the absolute path string starts with the target directory prefixSolution
The fix uses canonical paths and adds a file separator to the directory path check to prevent prefix matching attacks:
Test Coverage
Added comprehensive test cases in
ExpandTest.java
:../../evil.txt
)Verification
The fix is minimal and surgical, changing only 13 lines in the security-critical path validation logic.
Original prompt
Fixes #248
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.