Skip to content

Commit 7167792

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 f67c68e commit 7167792

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

core/src/main/java/org/projectodd/wunderboss/ApplicationRunner.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,7 @@
1818

1919
import org.slf4j.Logger;
2020

21-
import java.io.File;
22-
import java.io.FileInputStream;
23-
import java.io.FileOutputStream;
24-
import java.io.InputStream;
21+
import java.io.*;
2522
import java.net.MalformedURLException;
2623
import java.net.URL;
2724
import java.net.URLConnection;
@@ -125,7 +122,10 @@ public void run() {
125122
if (!match) {
126123
continue;
127124
}
128-
File file = new File(extractRoot + "/" + name);
125+
File file = new File(extractRoot, name);
126+
if (!file.toPath().normalize().startsWith(extractRoot)) {
127+
throw new IOException("Bad zip entry");
128+
}
129129
if (zipEntry.isDirectory()) {
130130
file.mkdirs();
131131
} else {

0 commit comments

Comments
 (0)