Skip to content

Commit 91643ad

Browse files
tausbnRasmusWL
andauthored
Python: Update hasUnsafeFilter to use API graph
This will probably break the tests in the short run. I'll fix the remaining issues in a follow-up commit. Co-authored-by: Rasmus Wriedt Larsen <[email protected]>
1 parent ad1a868 commit 91643ad

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

python/ql/lib/semmle/python/security/dataflow/TarSlipCustomizations.qll

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,19 +74,24 @@ module TarSlip {
7474
* Holds if `call` has an unsafe extraction filter, either by default (as the default is unsafe),
7575
* or by being set to an explicitly unsafe value, such as `"fully_trusted"`, or `None`.
7676
*/
77-
private predicate hasUnsafeFilter(DataFlow::CallCfgNode call) {
77+
private predicate hasUnsafeFilter(API::CallNode call) {
7878
call =
7979
API::moduleImport("tarfile")
8080
.getMember("open")
8181
.getReturn()
8282
.getMember(["extract", "extractall"])
8383
.getACall() and
8484
(
85-
call.getArg(4) = unsafeFilter()
86-
or
87-
call.getArgByName("filter") = unsafeFilter()
85+
exists(Expr filterValue |
86+
filterValue = call.getParameter(4, "filter").getAValueReachingSink().asExpr() and
87+
(
88+
filterValue.(StrConst).getText() = "fully_trusted"
89+
or
90+
filterValue instanceof None
91+
)
92+
)
8893
or
89-
not exists(call.getArg(4)) and not exists(call.getArgByName("filter"))
94+
not exists(call.getParameter(4, "filter"))
9095
)
9196
}
9297

0 commit comments

Comments
 (0)