Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,19 @@
* final InputStream is = Files.newInputStream(input.toPath());
* ArchiveInputStream in = new ArchiveStreamFactory().createArchiveInputStream(ArchiveStreamFactory.ZIP, is);
* ZipArchiveEntry entry = (ZipArchiveEntry) in.getNextEntry();
* OutputStream out = Files.newOutputStream(dir.toPath().resolve(entry.getName()));
* // ArchiveEntry.resolveIn(Path) normalizes the entry name and throws ArchiveException
* // if the result would escape the target directory (Zip Slip, CWE-22).
* OutputStream out = Files.newOutputStream(entry.resolveIn(dir.toPath()));
* IOUtils.copy(in, out);
* out.close();
* in.close();
* </pre>
*
* <p>Always resolve entry names through {@link ArchiveEntry#resolveIn(java.nio.file.Path)} rather than
* {@link java.nio.file.Path#resolve(java.nio.file.Path)}: entry names are attacker-controlled in untrusted archives and may
* contain {@code ..} segments that escape the target directory (Zip Slip, CWE-22). See also
* {@link org.apache.commons.compress.archivers.examples.Expander} for a ready-made safe extraction API.</p>
*
* @Immutable provided that the deprecated method setEntryEncoding is not used.
* @ThreadSafe even if the deprecated method setEntryEncoding is used
*/
Expand Down