Skip to content

Conversation

@slachiewicz
Copy link
Member


Co-authored-by: copilot-swe-agent[bot] 198982749+Copilot@users.noreply.github.com
Co-authored-by: slachiewicz 6705942+slachiewicz@users.noreply.github.com

(cherry picked from commit 6d780b3)

---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: slachiewicz <6705942+slachiewicz@users.noreply.github.com>

(cherry picked from commit 6d780b3)
@slachiewicz slachiewicz added the bug label Nov 9, 2025
@slachiewicz slachiewicz merged commit 36ea352 into plexus-utils-3.x Nov 9, 2025
12 of 14 checks passed
@slachiewicz slachiewicz deleted the zipfix branch November 9, 2025 11:47
@slachiewicz slachiewicz requested a review from Copilot January 10, 2026 22:43
Copy link

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 fixes a critical Zip Slip vulnerability in the archive extraction functionality. The Zip Slip vulnerability allows attackers to write files outside the intended extraction directory through malicious archive entries containing path traversal sequences (e.g., ../../evil.txt).

Changes:

  • Implemented path validation using canonical paths with proper separator checks to prevent directory traversal attacks
  • Added comprehensive test coverage for various Zip Slip attack vectors including parent directory traversal, absolute paths, and similar directory name exploits
  • Enhanced error handling for path verification failures

Reviewed changes

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

File Description
src/main/java/org/codehaus/plexus/util/Expand.java Implements canonical path validation with File.separator-based prefix checking to prevent path traversal attacks during archive extraction
src/test/java/org/codehaus/plexus/util/ExpandTest.java Adds comprehensive test coverage for Zip Slip vulnerability scenarios and verifies normal extraction still works correctly
Comments suppressed due to low confidence (1)

src/main/java/org/codehaus/plexus/util/Expand.java:151

  • Method extractFile ignores exceptional return value of File.setLastModified.
            f.setLastModified(entryDate.getTime());

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +125 to +126
} catch (IOException e) {
throw new IOException("Failed to verify entry path for '" + entryName + "'", e);
Copy link

Copilot AI Jan 10, 2026

Choose a reason for hiding this comment

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

The catch block will catch and re-wrap the IOException thrown by the security check at line 123, changing the error message from "Entry 'X' outside the target directory" to "Failed to verify entry path for 'X'". Consider catching the IOException from getCanonicalPath separately, or rethrowing the security exception without wrapping it to preserve the clearer error message.

Copilot uses AI. Check for mistakes.
targetDir.mkdirs();

// Create a malicious zip with absolute path
File evilTarget = new File("/tmp/evil-absolute.txt");
Copy link

Copilot AI Jan 10, 2026

Choose a reason for hiding this comment

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

The test uses a hardcoded absolute path '/tmp/evil-absolute.txt' which may not work correctly on all platforms (e.g., Windows systems). Consider using a path within the test directory or constructing a platform-appropriate absolute path for better cross-platform compatibility.

Suggested change
File evilTarget = new File("/tmp/evil-absolute.txt");
File evilTarget = new File(tempDir, "evil-absolute.txt").getAbsoluteFile();

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant