Skip to content

Fix COMPRESS-725: use ArchiveEntry.resolveIn() in the ArchiveStreamFactory Zip-Slip example - #842

Open
Inf1mum wants to merge 1 commit into
apache:masterfrom
Inf1mum:fix/COMPRESS-725-javadoc-zip-slip-example
Open

Inf1mum wants to merge 1 commit into
apache:masterfrom
Inf1mum:fix/COMPRESS-725-javadoc-zip-slip-example

Conversation

@Inf1mum

@Inf1mum Inf1mum commented Nov 16, 2026

Copy link
Copy Markdown

Fixes COMPRESS-725.

Problem

The decompression example in the class Javadoc of ArchiveStreamFactory resolved archive entry names with dir.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:

  • the example now extracts through entry.resolveIn(dir.toPath()), the safe helper available since 1.26.0, which normalizes the resolved path and throws ArchiveException when the result would escape the target directory;
  • a short paragraph after the example explains why entry names must be resolved through ArchiveEntry.resolveIn(Path) rather than Path.resolve(Path), and points readers at Expander for 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

  • Fork PRs on this repository require maintainer approval before CI runs, so the checks will initially sit at action_required — this is expected and normal.
  • An earlier attempt at this fix, #810, was self-closed by its own author on 2026-11-02 ("Closing this to keep my open PRs manageable. Happy to reopen and rebase if maintainers want it.") — it was not rejected. This PR delivers the same fix rebased onto current master.

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>
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.

1 participant