Skip to content

Commit 2d1114b

Browse files
Potential fix for code scanning alert no. 1: Arbitrary file access during archive extraction ("Zip Slip")
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
1 parent 66ba52a commit 2d1114b

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,16 @@ public List<String> list(URL url, String path) throws IOException {
8080
if (log.isLoggable(Level.FINER)) {
8181
log.log(Level.FINER, "Jar entry: " + entry.getName());
8282
}
83-
children.add(entry.getName());
83+
String entryName = entry.getName();
84+
File entryFile = new File(path, entryName).getCanonicalFile();
85+
File baseDir = new File(path).getCanonicalFile();
86+
if (!entryFile.toPath().startsWith(baseDir.toPath())) {
87+
if (log.isLoggable(Level.WARNING)) {
88+
log.log(Level.WARNING, "Skipping potentially unsafe entry: " + entryName);
89+
}
90+
continue;
91+
}
92+
children.add(entryName);
8493
}
8594
}
8695
} else {

0 commit comments

Comments
 (0)