Skip to content

Commit 5f7d3d0

Browse files
authored
Python: Use API graphs in Werkzeug
1 parent f341d50 commit 5f7d3d0

File tree

2 files changed

+16
-36
lines changed

2 files changed

+16
-36
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,13 +401,15 @@ module Flask {
401401
}
402402
}
403403

404-
private class RequestAttrMultiDict extends Werkzeug::werkzeug::datastructures::MultiDict::InstanceSource {
404+
private class RequestAttrMultiDict extends Werkzeug::werkzeug::datastructures::MultiDict::InstanceSourceApiNode {
405405
string attr_name;
406406

407407
RequestAttrMultiDict() {
408408
attr_name in ["args", "values", "form", "files"] and
409-
this = request().getMember(attr_name).getAnImmediateUse()
409+
this = request().getMember(attr_name)
410410
}
411+
412+
override string toString() { result = this.(API::Node).toString() }
411413
}
412414

413415
private class RequestAttrFiles extends RequestAttrMultiDict {

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

Lines changed: 12 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
private import python
66
private import semmle.python.dataflow.new.DataFlow
77
private import semmle.python.dataflow.new.TaintTracking
8+
private import semmle.python.ApiGraphs
89

910
/**
1011
* Provides models for the `Werkzeug` PyPI package.
@@ -23,6 +24,9 @@ module Werkzeug {
2324
* See https://werkzeug.palletsprojects.com/en/1.0.x/datastructures/#werkzeug.datastructures.MultiDict.
2425
*/
2526
module MultiDict {
27+
/** DEPRECATED. Use `InstanceSourceApiNode` instead. */
28+
abstract deprecated class InstanceSource extends DataFlow::Node { }
29+
2630
/**
2731
* A source of instances of `werkzeug.datastructures.MultiDict`, extend this class to model new instances.
2832
*
@@ -32,37 +36,16 @@ module Werkzeug {
3236
*
3337
* Use the predicate `MultiDict::instance()` to get references to instances of `werkzeug.datastructures.MultiDict`.
3438
*/
35-
abstract class InstanceSource extends DataFlow::Node { }
36-
37-
/** Gets a reference to an instance of `werkzeug.datastructures.MultiDict`. */
38-
private DataFlow::Node instance(DataFlow::TypeTracker t) {
39-
t.start() and
40-
result instanceof InstanceSource
41-
or
42-
exists(DataFlow::TypeTracker t2 | result = instance(t2).track(t2, t))
43-
}
44-
45-
/** Gets a reference to an instance of `werkzeug.datastructures.MultiDict`. */
46-
DataFlow::Node instance() { result = instance(DataFlow::TypeTracker::end()) }
39+
abstract class InstanceSourceApiNode extends API::Node { }
4740

4841
/**
4942
* Gets a reference to the `getlist` method on an instance of `werkzeug.datastructures.MultiDict`.
5043
*
5144
* See https://werkzeug.palletsprojects.com/en/1.0.x/datastructures/#werkzeug.datastructures.Headers.getlist
5245
*/
53-
private DataFlow::Node getlist(DataFlow::TypeTracker t) {
54-
t.startInAttr("getlist") and
55-
result = instance()
56-
or
57-
exists(DataFlow::TypeTracker t2 | result = getlist(t2).track(t2, t))
46+
DataFlow::Node getlist() {
47+
result = any(InstanceSourceApiNode a).getMember("getlist").getAUse()
5848
}
59-
60-
/**
61-
* Gets a reference to the `getlist` method on an instance of `werkzeug.datastructures.MultiDict`.
62-
*
63-
* See https://werkzeug.palletsprojects.com/en/1.0.x/datastructures/#werkzeug.datastructures.Headers.getlist
64-
*/
65-
DataFlow::Node getlist() { result = getlist(DataFlow::TypeTracker::end()) }
6649
}
6750

6851
/**
@@ -71,6 +54,9 @@ module Werkzeug {
7154
* See https://werkzeug.palletsprojects.com/en/1.0.x/datastructures/#werkzeug.datastructures.FileStorage.
7255
*/
7356
module FileStorage {
57+
/** DEPRECATED. Use `InstanceSourceApiNode` instead. */
58+
abstract deprecated class InstanceSource extends DataFlow::Node { }
59+
7460
/**
7561
* A source of instances of `werkzeug.datastructures.FileStorage`, extend this class to model new instances.
7662
*
@@ -80,18 +66,10 @@ module Werkzeug {
8066
*
8167
* Use the predicate `FileStorage::instance()` to get references to instances of `werkzeug.datastructures.FileStorage`.
8268
*/
83-
abstract class InstanceSource extends DataFlow::Node { }
84-
85-
/** Gets a reference to an instance of `werkzeug.datastructures.FileStorage`. */
86-
private DataFlow::Node instance(DataFlow::TypeTracker t) {
87-
t.start() and
88-
result instanceof InstanceSource
89-
or
90-
exists(DataFlow::TypeTracker t2 | result = instance(t2).track(t2, t))
91-
}
69+
abstract class InstanceSourceApiNode extends API::Node { }
9270

9371
/** Gets a reference to an instance of `werkzeug.datastructures.FileStorage`. */
94-
DataFlow::Node instance() { result = instance(DataFlow::TypeTracker::end()) }
72+
DataFlow::Node instance() { result = any(InstanceSourceApiNode a).getAUse() }
9573
}
9674
}
9775
}

0 commit comments

Comments
 (0)