Skip to content

Commit 3cdd875

Browse files
committed
Python: Move experimental UnsafeUnpack to new dataflow API
1 parent 3edb9d1 commit 3cdd875

File tree

3 files changed

+117
-28
lines changed

3 files changed

+117
-28
lines changed

python/ql/src/experimental/Security/CWE-022bis/UnsafeUnpack.ql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616

1717
import python
1818
import experimental.Security.UnsafeUnpackQuery
19-
import DataFlow::PathGraph
19+
import UnsafeUnpackFlow::PathGraph
2020

21-
from UnsafeUnpackingConfig config, DataFlow::PathNode source, DataFlow::PathNode sink
22-
where config.hasFlowPath(source, sink)
21+
from UnsafeUnpackFlow::PathNode source, UnsafeUnpackFlow::PathNode sink
22+
where UnsafeUnpackFlow::flowPath(source, sink)
2323
select sink.getNode(), source, sink,
2424
"Unsafe extraction from a malicious tarball retrieved from a remote location."

python/ql/src/experimental/Security/UnsafeUnpackQuery.qll

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,8 @@ class AllTarfileOpens extends API::CallNode {
3939
}
4040
}
4141

42-
class UnsafeUnpackingConfig extends TaintTracking::Configuration {
43-
UnsafeUnpackingConfig() { this = "UnsafeUnpackingConfig" }
44-
45-
override predicate isSource(DataFlow::Node source) {
42+
private module UnsafeUnpackConfig implements DataFlow::ConfigSig {
43+
predicate isSource(DataFlow::Node source) {
4644
// A source coming from a remote location
4745
source instanceof RemoteFlowSource
4846
or
@@ -92,7 +90,7 @@ class UnsafeUnpackingConfig extends TaintTracking::Configuration {
9290
source.(AttrRead).getAttributeName() = "FILES"
9391
}
9492

95-
override predicate isSink(DataFlow::Node sink) {
93+
predicate isSink(DataFlow::Node sink) {
9694
(
9795
// A sink capturing method calls to `unpack_archive`.
9896
sink = API::moduleImport("shutil").getMember("unpack_archive").getACall().getArg(0)
@@ -136,7 +134,7 @@ class UnsafeUnpackingConfig extends TaintTracking::Configuration {
136134
not sink.getScope().getLocation().getFile().inStdlib()
137135
}
138136

139-
override predicate isAdditionalTaintStep(DataFlow::Node nodeFrom, DataFlow::Node nodeTo) {
137+
predicate isAdditionalFlowStep(DataFlow::Node nodeFrom, DataFlow::Node nodeTo) {
140138
// Reading the response
141139
nodeTo.(MethodCallNode).calls(nodeFrom, "read")
142140
or
@@ -211,3 +209,6 @@ class UnsafeUnpackingConfig extends TaintTracking::Configuration {
211209
)
212210
}
213211
}
212+
213+
/** Global taint-tracking for detecting "UnsafeUnpacking" vulnerabilities. */
214+
module UnsafeUnpackFlow = TaintTracking::Global<UnsafeUnpackConfig>;

0 commit comments

Comments
 (0)