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 <rasmuswl@github.com>
This commit is contained in:
Taus
2023-11-28 14:48:26 +01:00
committed by GitHub
parent ad1a86879e
commit 91643ad08f

View File

@@ -74,7 +74,7 @@ module TarSlip {
* Holds if `call` has an unsafe extraction filter, either by default (as the default is unsafe),
* or by being set to an explicitly unsafe value, such as `"fully_trusted"`, or `None`.
*/
private predicate hasUnsafeFilter(DataFlow::CallCfgNode call) {
private predicate hasUnsafeFilter(API::CallNode call) {
call =
API::moduleImport("tarfile")
.getMember("open")
@@ -82,11 +82,16 @@ module TarSlip {
.getMember(["extract", "extractall"])
.getACall() and
(
call.getArg(4) = unsafeFilter()
exists(Expr filterValue |
filterValue = call.getParameter(4, "filter").getAValueReachingSink().asExpr() and
(
filterValue.(StrConst).getText() = "fully_trusted"
or
filterValue instanceof None
)
)
or
call.getArgByName("filter") = unsafeFilter()
or
not exists(call.getArg(4)) and not exists(call.getArgByName("filter"))
not exists(call.getParameter(4, "filter"))
)
}