GeezerVison is showing github.com — Fix Zip Slip vulnerability in archive extraction by Copilot · Pull Request #296 · codehaus-plexus/plexus-utils
Conversation
Copilot
AI
commented
Oct 10, 2025
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
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:
if (!f.getAbsolutePath().startsWith(dir.getAbsolutePath())) {
throw new IOException("Entry '" + entryName + "' outside the target directory.");
}
This check had two critical flaws:
- Used absolute paths instead of canonical paths: Didn't account for symbolic links or path normalization
- Vulnerable to prefix matching: A malicious entry could write to
/tmp/extract-evil/malicious.txt when extracting to /tmp/extract because the absolute path string starts with the target directory prefix
Solution
The fix uses canonical paths and adds a file separator to the directory path check to prevent prefix matching attacks:
try {
String canonicalDirPath = dir.getCanonicalPath();
String canonicalFilePath = f.getCanonicalPath();
// Ensure the file is within the target directory
// We need to check that the canonical file path starts with the canonical directory path
// followed by a file separator to prevent path traversal attacks
if (!canonicalFilePath.startsWith(canonicalDirPath + File.separator)
&& !canonicalFilePath.equals(canonicalDirPath)) {
throw new IOException("Entry '" + entryName + "' outside the target directory.");
}
} catch (IOException e) {
throw new IOException("Failed to verify entry path for '" + entryName + "'", e);
}
Test Coverage
Added comprehensive test cases in ExpandTest.java:
- Parent directory traversal attacks (
../../evil.txt)
- Absolute path attacks
- Prefix matching attacks (extracting to similarly-named directories)
- Regression test for normal zip extraction
Verification
- ✅ All 249 tests pass (4 new + 245 existing)
- ✅ CodeQL security scan confirms 0 vulnerabilities
- ✅ Code formatting and build checks pass
- ✅ No breaking changes to existing functionality
The fix is minimal and surgical, changing only 13 lines in the security-critical path validation logic.
Original prompt
This section details on the original issue you should resolve
<issue_title>Fix code scanning alert - Arbitrary file write during archive extraction ("Zip Slip")</issue_title>
<issue_description>
Tracking issue for:
Comments on the Issue (you are @copilot in this section)
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.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Copilot
AI
changed the title
[WIP] Fix code scanning alert for Zip Slip vulnerability
Fix Zip Slip vulnerability in archive extraction
Oct 10, 2025
|
Can we have this backported to 3.x line as well?
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
NVM, missed it is already backported to 3.x
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
@cstamas it has been backported but I don't see a 3.x release so it's still an issue, right?
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Right, 3.x branch has the fix, but 3.6.0 is last release, 3.6.1 yet to happen.
|
abelsromero reacted with confused emoji
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
gsmet
commented
Mar 31, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
|
@slachiewicz 👋 is there a plan for releasing a 3.x for Maven 3 consumption? Thanks!
|
headius reacted with heart emoji
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
We have had a request to update the ruby-maven-libs Ruby gem to include this change. ruby-maven-libs is just a container for a complete Maven 3.x distribution, and we would prefer not to have to patch individual elements of that distribution. Therefore we are also interested in this update getting into a Maven 3 release.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Plexus Utils 3.6.1 w/ fix is released. For Maven 3.9.x it may take some more time. Also, Maven 3.10.x is in preparation (goal is Resolver 2.x shipped with it).
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This was referenced May 29, 2026
Uh oh!
There was an error while loading. Please reload this page.
Labels
bug
Something isn't working
Milestone
No milestone
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.
|