Skip to content

Conversation

@th555555
Copy link

Description

This pull request addresses a critical security vulnerability in the deleteRecursive method. The current implementation has no path validation, making it susceptible to path traversal attacks that could allow deletion of files outside the intended directory.

Security Impact

Vulnerability Type: Path Traversal (CWE-22)
Severity: High
Impact: Potential unauthorized deletion of files anywhere on the filesystem Attack Vector: Any code path that allows user-controlled input to reach this method Changes Made
Added a required base directory parameter to establish a security boundary Implemented path validation using canonical file paths and Java NIO Path comparisons Added existence check for files before attempting to delete Changed exception type to IOException for consistency with file operations Added detailed error message for security violations

References

AdoptOpenJDK/IcedTea-Web@b09c6a4
https://cwe.mitre.org/data/definitions/22.html

@lessthanoptimal lessthanoptimal self-requested a review September 20, 2025 18:52
Description
This pull request addresses a critical security vulnerability in the deleteRecursive method. The current implementation has no path validation, making it susceptible to path traversal attacks that could allow deletion of files outside the intended directory.

Security Impact
Vulnerability Type: Path Traversal (CWE-22)
Severity: High
Impact: Potential unauthorized deletion of files anywhere on the filesystem
Attack Vector: Any code path that allows user-controlled input to reach this method
Changes Made
Added a required base directory parameter to establish a security boundary
Implemented path validation using canonical file paths and Java NIO Path comparisons
Added existence check for files before attempting to delete
Changed exception type to IOException for consistency with file operations
Added detailed error message for security violations

References
AdoptOpenJDK/IcedTea-Web@b09c6a4
https://cwe.mitre.org/data/definitions/22.html
Description
This pull request addresses a critical security vulnerability in the decompressZip method that could allow attackers to overwrite arbitrary files on the system using specially crafted ZIP archives.

Security Impact
Vulnerability Type: Path Traversal / Zip Slip (CWE-22)
Severity: High
Impact: Unauthorized file write to any location where the application has write permissions
Attack Vector: Processing malicious ZIP archives containing entries with path traversal sequences (e.g., "../../../dangerous-path")
Changes Made
Added path validation to ensure extracted files stay within the target directory
Added explicit error handling for malicious ZIP entries
Preserved all existing functionality (including the delete parameter)

References:
https://cwe.mitre.org/data/definitions/22.html
Copy link
Owner

@lessthanoptimal lessthanoptimal left a comment

Choose a reason for hiding this comment

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

deleteRecursive doesn't build and needs a variable defined. Also add a comment explaining why this check is needed. I'm assuming it's because maybe a symbolic link or shortcut could reference something outside? Bonus points if you add a simple unit test that triggers this new code.

Thanks for the PR! I can see how these could be a security issue.

}

// Security check: ensure we're only deleting files within the base directory
if (!(f.getCanonicalFile().toPath().startsWith(baseDir.getCanonicalFile().toPath()))) {
Copy link
Owner

Choose a reason for hiding this comment

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

baseDir is not defined

}

// Security check: ensure we're only deleting files within the base directory
if (!(f.getCanonicalFile().toPath().startsWith(baseDir.getCanonicalFile().toPath()))) {
Copy link
Owner

Choose a reason for hiding this comment

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

You need to catch and re-throw IOExceptions

if (entry.isDirectory()) {

// Security check to prevent zip slip vulnerability
if (!entryDestination.getCanonicalPath().startsWith(targetPath)) {
Copy link
Owner

Choose a reason for hiding this comment

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

I did not know a zip file could reference a parent path? I'll look at your references.

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