Skip to content

Commit fbc6c5a

Browse files
vuln-fix: Zip Slip Vulnerability
This fixes a Zip-Slip vulnerability. This change does one of two things. This change either 1. Inserts a guard to protect against Zip Slip. OR 2. Replaces `dir.getCanonicalPath().startsWith(parent.getCanonicalPath())`, which is vulnerable to partial path traversal attacks, with the more secure `dir.getCanonicalFile().toPath().startsWith(parent.getCanonicalFile().toPath())`. For number 2, consider `"/usr/outnot".startsWith("/usr/out")`. The check is bypassed although `/outnot` is not under the `/out` directory. It's important to understand that the terminating slash may be removed when using various `String` representations of the `File` object. For example, on Linux, `println(new File("/var"))` will print `/var`, but `println(new File("/var", "/")` will print `/var/`; however, `println(new File("/var", "/").getCanonicalPath())` will print `/var`. Weakness: CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal') Severity: High CVSSS: 7.4 Detection: CodeQL (https://codeql.github.com/codeql-query-help/java/java-zipslip/) & OpenRewrite (https://public.moderne.io/recipes/org.openrewrite.java.security.ZipSlip) Reported-by: Jonathan Leitschuh <[email protected]> Signed-off-by: Jonathan Leitschuh <[email protected]> Bug-tracker: JLLeitschuh/security-research#16 Co-authored-by: Moderne <[email protected]>
1 parent 93a5795 commit fbc6c5a

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

graph-builder/src/main/java/spoon/decompiler/FernflowerDecompiler.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,10 @@ private void unzipJar(String toBeExtractedJar, String destDir) throws IOExceptio
6666
java.util.Enumeration enumEntries = jar.entries();
6767
while (enumEntries.hasMoreElements()) {
6868
java.util.jar.JarEntry file = (java.util.jar.JarEntry) enumEntries.nextElement();
69-
java.io.File f = new java.io.File(destDir + java.io.File.separator + file.getName());
69+
java.io.File f = new File(destDir, file.getName());
70+
if(!f.toPath().normalize().startsWith(destDir)) {
71+
throw new IOException("Bad zip entry");
72+
}
7073
f.getParentFile().mkdirs();
7174
if (file.isDirectory()) { // if its a directory, create it
7275
f.mkdir();

0 commit comments

Comments
 (0)