Skip to content

Commit 5d8329d

Browse files
committed
Python: Move experimental ZipSlip to new dataflow API
1 parent 67cc3a3 commit 5d8329d

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

python/ql/src/experimental/Security/CWE-022/ZipSlip.ql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515

1616
import python
1717
import experimental.semmle.python.security.ZipSlip
18-
import DataFlow::PathGraph
18+
import ZipSlipFlow::PathGraph
1919

20-
from ZipSlipConfig config, DataFlow::PathNode source, DataFlow::PathNode sink
21-
where config.hasFlowPath(source, sink)
20+
from ZipSlipFlow::PathNode source, ZipSlipFlow::PathNode sink
21+
where ZipSlipFlow::flowPath(source, sink)
2222
select source.getNode(), source, sink,
2323
"This unsanitized archive entry, which may contain '..', is used in a $@.", sink.getNode(),
2424
"file system operation"

python/ql/src/experimental/semmle/python/security/ZipSlip.qll

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@ import semmle.python.dataflow.new.DataFlow
44
import semmle.python.ApiGraphs
55
import semmle.python.dataflow.new.TaintTracking
66

7-
class ZipSlipConfig extends TaintTracking::Configuration {
8-
ZipSlipConfig() { this = "ZipSlipConfig" }
9-
10-
override predicate isSource(DataFlow::Node source) {
7+
private module ZipSlipConfig implements DataFlow::ConfigSig {
8+
predicate isSource(DataFlow::Node source) {
119
(
1210
source =
1311
API::moduleImport("zipfile").getMember("ZipFile").getReturn().getMember("open").getACall() or
@@ -29,11 +27,14 @@ class ZipSlipConfig extends TaintTracking::Configuration {
2927
not source.getScope().getLocation().getFile().inStdlib()
3028
}
3129

32-
override predicate isSink(DataFlow::Node sink) {
30+
predicate isSink(DataFlow::Node sink) {
3331
(
3432
sink = any(CopyFile copyfile).getAPathArgument() or
3533
sink = any(CopyFile copyfile).getfsrcArgument()
3634
) and
3735
not sink.getScope().getLocation().getFile().inStdlib()
3836
}
3937
}
38+
39+
/** Global taint-tracking for detecting "zip slip" vulnerabilities. */
40+
module ZipSlipFlow = TaintTracking::Global<ZipSlipConfig>;

0 commit comments

Comments
 (0)