-
Notifications
You must be signed in to change notification settings - Fork 267
Fix Path Traversal Vulnerability in deleteRecursive Method #447
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: SNAPSHOT
Are you sure you want to change the base?
Conversation
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
1f837b9 to
8a138c3
Compare
There was a problem hiding this 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()))) { |
There was a problem hiding this comment.
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()))) { |
There was a problem hiding this comment.
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)) { |
There was a problem hiding this comment.
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.
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