Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ba19f95

Browse files
committed
Python: Improve SelfRefMixin
This is important to model mixins correctly, for example when they help handle incoming requests, and therefore need to know that `self.kwargs` contains data controlled by a user.
1 parent dfdb66f commit ba19f95

1 file changed

Lines changed: 8 additions & 7 deletions

File tree

python/ql/lib/semmle/python/frameworks/internal/SelfRefMixin.qll

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
private import python
88
private import semmle.python.dataflow.new.DataFlow
9+
private import semmle.python.dataflow.new.internal.DataFlowDispatch
910

1011
/**
1112
* INTERNAL: Do not use.
@@ -16,23 +17,23 @@ abstract class SelfRefMixin extends Class {
1617
/**
1718
* Gets a reference to instances of this class, originating from a self parameter of
1819
* a method defined on this class.
19-
*
20-
* Note: TODO: This doesn't take MRO into account
21-
* Note: TODO: This doesn't take staticmethod/classmethod into account
2220
*/
2321
private DataFlow::TypeTrackingNode getASelfRef(DataFlow::TypeTracker t) {
2422
t.start() and
25-
result.(DataFlow::ParameterNode).getParameter() = this.getAMethod().getArg(0)
23+
exists(Class cls, Function meth |
24+
cls = getADirectSuperclass*(this) and
25+
meth = cls.getAMethod() and
26+
not isStaticmethod(meth) and
27+
not isClassmethod(meth) and
28+
result.(DataFlow::ParameterNode).getParameter() = meth.getArg(0)
29+
)
2630
or
2731
exists(DataFlow::TypeTracker t2 | result = this.getASelfRef(t2).track(t2, t))
2832
}
2933

3034
/**
3135
* Gets a reference to instances of this class, originating from a self parameter of
3236
* a method defined on this class.
33-
*
34-
* Note: TODO: This doesn't take MRO into account
35-
* Note: TODO: This doesn't take staticmethod/classmethod into account
3637
*/
3738
DataFlow::Node getASelfRef() { this.getASelfRef(DataFlow::TypeTracker::end()).flowsTo(result) }
3839
}

0 commit comments

Comments
 (0)