Skip to content

Commit ab81247

Browse files
authored
Python: Fix modelling in ZipSlip.qll
- Remove use of points-to. - Exclude sources and sinks in the standard library (to prevent test brittleness).
1 parent 57beeaa commit ab81247

File tree

1 file changed

+27
-15
lines changed
  • python/ql/src/experimental/semmle/python/security

1 file changed

+27
-15
lines changed

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

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,33 @@ import semmle.python.dataflow.new.TaintTracking
77
class ZipSlipConfig extends TaintTracking::Configuration {
88
ZipSlipConfig() { this = "ZipSlipConfig" }
99

10-
override predicate isSource(DataFlow::Node source) {
11-
source.asCfgNode().(CallNode).getFunction().(AttrNode).getObject("open").pointsTo().getClass() = Module::named("zipfile").attr("ZipFile") or
12-
source.asCfgNode().(CallNode).getFunction().(AttrNode).getObject("namelist").pointsTo().getClass() = Module::named("zipfile").attr("ZipFile") or
13-
source = API::moduleImport("tarfile").getMember("open").getACall() or
14-
source = API::moduleImport("tarfile").getMember("TarFile").getACall() or
15-
source = API::moduleImport("bz2").getMember("open").getACall() or
16-
source = API::moduleImport("bz2").getMember("BZ2File").getACall() or
17-
source = API::moduleImport("gzip").getMember("GzipFile").getACall() or
18-
source = API::moduleImport("gzip").getMember("open").getACall() or
19-
source = API::moduleImport("lzma").getMember("open").getACall() or
20-
source = API::moduleImport("lzma").getMember("LZMAFile").getACall()
10+
override predicate isSource(DataFlow::Node source) {
11+
(
12+
source =
13+
API::moduleImport("zipfile").getMember("ZipFile").getReturn().getMember("open").getACall() or
14+
source =
15+
API::moduleImport("zipfile")
16+
.getMember("ZipFile")
17+
.getReturn()
18+
.getMember("namelist")
19+
.getACall() or
20+
source = API::moduleImport("tarfile").getMember("open").getACall() or
21+
source = API::moduleImport("tarfile").getMember("TarFile").getACall() or
22+
source = API::moduleImport("bz2").getMember("open").getACall() or
23+
source = API::moduleImport("bz2").getMember("BZ2File").getACall() or
24+
source = API::moduleImport("gzip").getMember("GzipFile").getACall() or
25+
source = API::moduleImport("gzip").getMember("open").getACall() or
26+
source = API::moduleImport("lzma").getMember("open").getACall() or
27+
source = API::moduleImport("lzma").getMember("LZMAFile").getACall()
28+
) and
29+
not source.getScope().getLocation().getFile().inStdlib()
2130
}
22-
23-
override predicate isSink(DataFlow::Node sink) {
24-
sink = any(CopyFile copyfile).getAPathArgument() or
25-
sink = any(CopyFile copyfile).getfsrcArgument()
31+
32+
override predicate isSink(DataFlow::Node sink) {
33+
(
34+
sink = any(CopyFile copyfile).getAPathArgument() or
35+
sink = any(CopyFile copyfile).getfsrcArgument()
36+
) and
37+
not sink.getScope().getLocation().getFile().inStdlib()
2638
}
2739
}

0 commit comments

Comments
 (0)