Skip to content

Commit

Permalink
Merge pull request #3250 from mybatis/autofix/alert-7-b48d877adc
Browse files Browse the repository at this point in the history
Fix code scanning alert no. 7: Arbitrary file access during archive extraction ("Zip Slip")
  • Loading branch information
hazendaz authored Sep 26, 2024
2 parents 7194767 + ec07133 commit 45953df
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/main/java/org/apache/ibatis/io/DefaultVFS.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,15 @@ public List<String> list(URL url, String path) throws IOException {
if (log.isDebugEnabled()) {
log.debug("Listing " + url);
}
File destinationDir = new File(path);
for (JarEntry entry; (entry = jarInput.getNextJarEntry()) != null;) {
if (log.isDebugEnabled()) {
log.debug("Jar entry: " + entry.getName());
}
File entryFile = new File(destinationDir, entry.getName()).getCanonicalFile();
if (!entryFile.getPath().startsWith(destinationDir.getCanonicalPath())) {
throw new IOException("Bad zip entry: " + entry.getName());
}
children.add(entry.getName());
}
}
Expand Down

0 comments on commit 45953df

Please sign in to comment.