Skip to content

Commit d19bc12

Browse files
committed
Python: limit size of extraStepForCalls predicate
On django/django, this reduced the number of results in `extraStepForCalls` from 201,283 to 541
1 parent dee9378 commit d19bc12

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

python/ql/src/semmle/python/dataflow/new/SensitiveDataSources.qll

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,25 @@ private module SensitiveDataModeling {
115115
override SensitiveDataClassification getClassification() { result = classification }
116116
}
117117

118+
/**
119+
* Tracks any modeled source of sensitive data (with any classification),
120+
* to limit the scope of `extraStepForCalls`. See it's QLDoc for more context.
121+
*/
122+
private DataFlow::LocalSourceNode possibleSensitiveCallable(DataFlow::TypeTracker t) {
123+
t.start() and
124+
result instanceof SensitiveDataSource
125+
or
126+
exists(DataFlow::TypeTracker t2 | result = possibleSensitiveCallable(t2).track(t2, t))
127+
}
128+
129+
/**
130+
* Tracks any modeled source of sensitive data (with any classification),
131+
* to limit the scope of `extraStepForCalls`. See it's QLDoc for more context.
132+
*/
133+
private DataFlow::Node possibleSensitiveCallable() {
134+
possibleSensitiveCallable(DataFlow::TypeTracker::end()).flowsTo(result)
135+
}
136+
118137
/**
119138
* Holds if the step from `nodeFrom` to `nodeTo` should be considered a
120139
* taint-flow step for sensitive-data, to ensure calls are handled correctly.
@@ -147,7 +166,10 @@ private module SensitiveDataModeling {
147166
* ```
148167
*/
149168
predicate extraStepForCalls(DataFlow::Node nodeFrom, DataFlow::CallCfgNode nodeTo) {
150-
nodeTo.getFunction() = nodeFrom
169+
// However, we do still use the type-tracking approach to limit the size of this
170+
// predicate.
171+
nodeTo.getFunction() = nodeFrom and
172+
nodeFrom = possibleSensitiveCallable()
151173
}
152174

153175
/**

0 commit comments

Comments
 (0)