Skip to content

Commit 45953df

Browse files
authored
Merge pull request #3250 from mybatis/autofix/alert-7-b48d877adc
Fix code scanning alert no. 7: Arbitrary file access during archive extraction ("Zip Slip")
2 parents 7194767 + ec07133 commit 45953df

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/main/java/org/apache/ibatis/io/DefaultVFS.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,15 @@ public List<String> list(URL url, String path) throws IOException {
7979
if (log.isDebugEnabled()) {
8080
log.debug("Listing " + url);
8181
}
82+
File destinationDir = new File(path);
8283
for (JarEntry entry; (entry = jarInput.getNextJarEntry()) != null;) {
8384
if (log.isDebugEnabled()) {
8485
log.debug("Jar entry: " + entry.getName());
8586
}
87+
File entryFile = new File(destinationDir, entry.getName()).getCanonicalFile();
88+
if (!entryFile.getPath().startsWith(destinationDir.getCanonicalPath())) {
89+
throw new IOException("Bad zip entry: " + entry.getName());
90+
}
8691
children.add(entry.getName());
8792
}
8893
}

0 commit comments

Comments
 (0)