Zip Slip (ARCH4106)
Ce contenu n’est pas encore disponible dans votre langue.
Key java.security.zip-slip · Severity error · Category security · CWE CWE-22
Writing archive entry paths to disk without verifying they stay within the target directory lets entry names containing ../ write files outside the intended directory.
Incorrect
Section titled “Incorrect”ZipEntry e = zip.getNextEntry();File out = new File(targetDir, e.getName());Files.copy(zip, out.toPath());Correct
Section titled “Correct”Path base = targetDir.toPath().toRealPath();Path out = base.resolve(e.getName()).normalize();if (!out.startsWith(base)) throw new IOException("Zip slip: " + e.getName());Files.copy(zip, out);Resolve and normalize each entry path and verify it stays within the target directory before writing to disk.