Skip to content

Commit acbe053

Browse files
eddieh-xlnxJLLeitschuhclavin-xlnx
authored
vuln-fix: Zip Slip Vulnerability (#536)
* 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]> Signed-off-by: Eddie Hung <[email protected]> Conflicts: test/RapidWrightDCP * Update src/com/xilinx/rapidwright/util/Installer.java Signed-off-by: Chris Lavin <[email protected]> Signed-off-by: Chris Lavin <[email protected]> Co-authored-by: Jonathan Leitschuh <[email protected]> Co-authored-by: Chris Lavin <[email protected]>
1 parent a9f09a5 commit acbe053

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/com/xilinx/rapidwright/util/Installer.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,10 @@ public static void unzipFile(String zipFile, String destDir) {
200200
ZipEntry ze = zis.getNextEntry();
201201
while(ze != null){
202202
String fileName = ze.getName();
203-
File newFile = new File(destDir + File.separator + fileName);
203+
File newFile = new File(destDir, fileName);
204+
if(!newFile.toPath().normalize().startsWith(destDir)) {
205+
throw new RuntimeException("Bad zip entry");
206+
}
204207
System.out.println("Unzipping to "+newFile.getAbsolutePath());
205208

206209
if(ze.isDirectory()){

0 commit comments

Comments
 (0)