Repository navigation
Conversation
What: Replace the decompression example in ArchiveStreamFactory Javadoc that resolved archive entry names with dir.toPath().resolve(entry.getName()) with the safe ArchiveEntry.resolveIn(dir.toPath()) API, and add a short paragraph explaining why entry names must not be resolved directly. Why: The documented example taught a pattern that is vulnerable to Zip Slip path traversal (CWE-22): entry names in untrusted archives may contain '..' segments that escape the target directory. Fixes COMPRESS-725. https://issues.apache.org/jira/browse/COMPRESS-725 How: Use entry.resolveIn(dir.toPath()) in the example, which normalizes the resolved path and throws ArchiveException when it would escape the parent directory (available since 1.26.0). Document the pitfall and point readers at Expander for a ready-made safe extraction API. Signed-off-by: Inf1mum <vadimlazuk5@gmail.com>
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.
Fixes COMPRESS-725.
Problem
The decompression example in the class Javadoc of
ArchiveStreamFactoryresolved archive entry names withdir.toPath().resolve(entry.getName()). Entry names in untrusted archives are attacker-controlled and may contain..segments, so the documented pattern teaches an extraction loop vulnerable to Zip Slip path traversal (CWE-22), the issue reported in COMPRESS-725.Change
Documentation only:
entry.resolveIn(dir.toPath()), the safe helper available since 1.26.0, which normalizes the resolved path and throwsArchiveExceptionwhen the result would escape the target directory;ArchiveEntry.resolveIn(Path)rather thanPath.resolve(Path), and points readers atExpanderfor a ready-made safe extraction API.Verification
javadoc:javadoc: BUILD SUCCESS, no warnings or errors;mvn verify(includes apache-rat, checkstyle, japicmp): BUILD SUCCESS, no API differences reported.Notes for reviewers
action_required— this is expected and normal.