Skip to content

Commit f5ae5a5

Browse files
committed
Python: A bit more additional taint clean up
A few stragglers that did not have the same TODO comments as the others
1 parent d2efe0b commit f5ae5a5

File tree

2 files changed

+13
-62
lines changed

2 files changed

+13
-62
lines changed

python/ql/src/semmle/python/frameworks/Flask.qll

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -347,17 +347,9 @@ module Flask {
347347
*/
348348
private class FlaskRequestAdditionalTaintStep extends TaintTracking::AdditionalTaintStep {
349349
override predicate step(DataFlow::Node nodeFrom, DataFlow::Node nodeTo) {
350-
// Methods
351-
exists(string method_name | method_name in ["get_data", "get_json"] |
352-
// Method access
353-
nodeFrom = request().getAUse() and
354-
nodeTo.(DataFlow::AttrRead).getObject() = nodeFrom and
355-
nodeTo.(DataFlow::AttrRead).getAttributeName() = method_name
356-
or
357-
// Method call
358-
nodeFrom = request().getMember(method_name).getAUse() and
359-
nodeTo.(DataFlow::CallCfgNode).getFunction() = nodeFrom
360-
)
350+
// normal (non-async) methods
351+
nodeFrom = request().getAUse() and
352+
nodeTo.(DataFlow::MethodCallNode).calls(nodeFrom, ["get_data", "get_json"])
361353
or
362354
// Attributes
363355
nodeFrom = request().getAUse() and

python/ql/src/semmle/python/frameworks/Tornado.qll

Lines changed: 10 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -138,32 +138,6 @@ private module Tornado {
138138
/** Gets a reference to an instance of the `tornado.web.RequestHandler` class or any subclass. */
139139
DataFlow::Node instance() { instance(DataFlow::TypeTracker::end()).flowsTo(result) }
140140

141-
/** Gets a reference to one of the methods `get_argument`, `get_body_argument`, `get_query_argument`. */
142-
private DataFlow::TypeTrackingNode argumentMethod(DataFlow::TypeTracker t) {
143-
t.startInAttr(["get_argument", "get_body_argument", "get_query_argument"]) and
144-
result = instance()
145-
or
146-
exists(DataFlow::TypeTracker t2 | result = argumentMethod(t2).track(t2, t))
147-
}
148-
149-
/** Gets a reference to one of the methods `get_argument`, `get_body_argument`, `get_query_argument`. */
150-
DataFlow::Node argumentMethod() {
151-
argumentMethod(DataFlow::TypeTracker::end()).flowsTo(result)
152-
}
153-
154-
/** Gets a reference to one of the methods `get_arguments`, `get_body_arguments`, `get_query_arguments`. */
155-
private DataFlow::TypeTrackingNode argumentsMethod(DataFlow::TypeTracker t) {
156-
t.startInAttr(["get_arguments", "get_body_arguments", "get_query_arguments"]) and
157-
result = instance()
158-
or
159-
exists(DataFlow::TypeTracker t2 | result = argumentsMethod(t2).track(t2, t))
160-
}
161-
162-
/** Gets a reference to one of the methods `get_arguments`, `get_body_arguments`, `get_query_arguments`. */
163-
DataFlow::Node argumentsMethod() {
164-
argumentsMethod(DataFlow::TypeTracker::end()).flowsTo(result)
165-
}
166-
167141
/** Gets a reference the `redirect` method. */
168142
private DataFlow::TypeTrackingNode redirectMethod(DataFlow::TypeTracker t) {
169143
t.startInAttr("redirect") and
@@ -190,14 +164,15 @@ private module Tornado {
190164

191165
private class AdditionalTaintStep extends TaintTracking::AdditionalTaintStep {
192166
override predicate step(DataFlow::Node nodeFrom, DataFlow::Node nodeTo) {
193-
// Method access
194-
nodeTo.(DataFlow::AttrRead).getObject() = nodeFrom and
167+
// normal (non-async) methods
195168
nodeFrom = instance() and
196-
nodeTo in [argumentMethod(), argumentsMethod()]
197-
or
198-
// Method call
199-
nodeTo.asCfgNode().(CallNode).getFunction() = nodeFrom.asCfgNode() and
200-
nodeFrom in [argumentMethod(), argumentsMethod()]
169+
nodeTo
170+
.(DataFlow::MethodCallNode)
171+
.calls(nodeFrom,
172+
[
173+
"get_argument", "get_body_argument", "get_query_argument", "get_arguments",
174+
"get_body_arguments", "get_query_arguments"
175+
])
201176
or
202177
// Attributes
203178
nodeFrom = instance() and
@@ -315,27 +290,11 @@ private module Tornado {
315290
/** Gets a reference to an instance of `tornado.httputil.HttpServerRequest`. */
316291
DataFlow::Node instance() { instance(DataFlow::TypeTracker::end()).flowsTo(result) }
317292

318-
/** Gets a reference to the `full_url` method. */
319-
private DataFlow::TypeTrackingNode full_url(DataFlow::TypeTracker t) {
320-
t.startInAttr("full_url") and
321-
result = instance()
322-
or
323-
exists(DataFlow::TypeTracker t2 | result = full_url(t2).track(t2, t))
324-
}
325-
326-
/** Gets a reference to the `full_url` method. */
327-
DataFlow::Node full_url() { full_url(DataFlow::TypeTracker::end()).flowsTo(result) }
328-
329293
private class AdditionalTaintStep extends TaintTracking::AdditionalTaintStep {
330294
override predicate step(DataFlow::Node nodeFrom, DataFlow::Node nodeTo) {
331-
// Method access
332-
nodeTo.(DataFlow::AttrRead).getObject() = nodeFrom and
295+
// normal (non-async) methods
333296
nodeFrom = instance() and
334-
nodeTo in [full_url()]
335-
or
336-
// Method call
337-
nodeTo.asCfgNode().(CallNode).getFunction() = nodeFrom.asCfgNode() and
338-
nodeFrom in [full_url()]
297+
nodeTo.(DataFlow::MethodCallNode).calls(nodeFrom, ["full_url"])
339298
or
340299
// Attributes
341300
nodeFrom = instance() and

0 commit comments

Comments
 (0)