Restrict entry names which resolve to output directory itself - #589
Open
Marcono1234 wants to merge 1 commit into
Open
Restrict entry names which resolve to output directory itself#589Marcono1234 wants to merge 1 commit into
Marcono1234 wants to merge 1 commit into
Conversation
Marcono1234
commented
Jun 30, 2026
| } | ||
| } | ||
|
|
||
| private void assertCanonicalPathsAreSame(File outputFile, String outputPath, FileHeader fileHeader) |
Contributor
Author
There was a problem hiding this comment.
Combined this with the determineOutputFile method to support using null as indication to skip the ZIP entry, but without causing a ZipException.
Comment on lines
+201
to
+205
| // Assume a redundant `/` entry is non-malicious but skip processing it to avoid modifying output | ||
| // directory in some way (e.g. changing file permissions) | ||
| if (outputFileName.equals(InternalZipConstants.ZIP_FILE_SEPARATOR)) { | ||
| return null; | ||
| } |
Contributor
Author
There was a problem hiding this comment.
I vaguely remember that I read that some (non-malicious) tools create such / entry, but I might be misremembering it.
If you don't think this is necessary, and a / entry should be treated as error as well instead of being skipped, please let me know.
Marcono1234
marked this pull request as draft
June 30, 2026 16:30
Marcono1234
force-pushed
the
zip-slip-output-dir
branch
from
June 30, 2026 17:29
5790134 to
3855710
Compare
Marcono1234
marked this pull request as ready for review
June 30, 2026 17:49
Contributor
Author
|
The CI error seems unrelated? |
Marcono1234
force-pushed
the
zip-slip-output-dir
branch
from
July 1, 2026 16:55
3855710 to
d3cc017
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
When extracting a ZIP file with entries named
.,/or similar, those entries refer to the output directory itself. This PR restricts these entry name to avoid modifications (such as file permission changes) to the output directory.Here is a small sample which previously caused Zip4j to erroneously modify the permissions of the output directory. The example uses the Apache Commons Compress library to create the ZIP file because that library makes it a bit easier to set these ZIP entry attributes.