Skip to content

Commit 1a21148

Browse files
committed
Restrain the source and add two steps.
1 parent 51b11de commit 1a21148

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

python/ql/src/experimental/Security/CWE-022bis/UnsafeUnpackQuery.qll

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,9 @@ class UnsafeUnpackingConfig extends TaintTracking::Configuration {
5050
)
5151
)
5252
or
53-
// catch the uploaded files as a source
54-
exists(Subscript s, Attribute at |
55-
at = s.getObject() and at.getAttr() = "FILES" and source.asExpr() = s
56-
)
57-
or
58-
// Retrieve Django uploaded files
53+
// catch the Django uploaded files as a source
5954
// see HttpRequest.FILES: https://docs.djangoproject.com/en/4.1/ref/request-response/#django.http.HttpRequest.FILES
60-
exists(Node obj, AttrRead ar |
61-
ar.getAMethodCall(["getlist", "get"]).flowsTo(source) and
62-
ar.accesses(obj, "FILES")
63-
)
55+
source.(AttrRead).getAttributeName() = "FILES"
6456
}
6557

6658
override predicate isSink(DataFlow::Node sink) {
@@ -107,6 +99,12 @@ class UnsafeUnpackingConfig extends TaintTracking::Configuration {
10799
nodeFrom = cn.getArg(0)
108100
)
109101
or
102+
// Retrieve Django uploaded files
103+
// see HttpRequest.FILES.getlist(): https://docs.djangoproject.com/en/4.1/ref/request-response/#django.http.QueryDict.getlist
104+
exists(MethodCallNode mc |
105+
nodeFrom = mc.getObject() and mc.getMethodName() = ["getlist", "get"] and nodeTo = mc
106+
)
107+
or
110108
// Accessing the name or raw content
111109
exists(AttrRead ar | ar.accesses(nodeFrom, ["name", "raw"]) and ar.flowsTo(nodeTo))
112110
or

0 commit comments

Comments
 (0)