mirror of
https://github.com/github/codeql.git
synced 2026-04-30 03:05:15 +02:00
Java: Add a flow step for Path::toFile in ZipSlip
This commit is contained in:
@@ -79,6 +79,8 @@ predicate filePathStep(ExprNode n1, ExprNode n2) {
|
||||
m.getDeclaringType() instanceof TypeFile and m.hasName("toPath")
|
||||
or
|
||||
m.getDeclaringType() instanceof TypePath and m.hasName("toAbsolutePath")
|
||||
or
|
||||
m.getDeclaringType() instanceof TypePath and m.hasName("toFile")
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -51,4 +51,13 @@ public class ZipTest {
|
||||
throw new Exception();
|
||||
FileOutputStream os = new FileOutputStream(file); // OK
|
||||
}
|
||||
|
||||
public void m6(ZipEntry entry, Path dir) {
|
||||
String canonicalDest = dir.toFile().getCanonicalPath();
|
||||
Path target = dir.resolve(entry.getName());
|
||||
String canonicalTarget = target.toFile().getCanonicalPath();
|
||||
if (!canonicalTarget.startsWith(canonicalDest + File.separator))
|
||||
throw new Exception();
|
||||
OutputStream os = Files.newOutputStream(target); // OK
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user