Skip to content

Commit 79696c6

Browse files
authored
Merge pull request #9572 from erik-krogh/heuristicSteps
JS: add heuristic taint-step for potentially unmodelled libraries
2 parents 7010dff + ce323e2 commit 79696c6

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

javascript/ql/lib/semmle/javascript/heuristics/AdditionalTaintSteps.qll

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,15 @@ private class HeuristicStringManipulationTaintStep extends TaintTracking::Shared
1717
)
1818
}
1919
}
20+
21+
/** Any call to a library component where we assume taint from any argument to the result */
22+
private class HeuristicLibraryCallTaintStep extends TaintTracking::SharedTaintStep {
23+
override predicate heuristicStep(DataFlow::Node pred, DataFlow::Node succ) {
24+
exists(API::CallNode call |
25+
pred = call.getAnArgument() or // the plain argument
26+
pred = call.getAnArgument().(DataFlow::SourceNode).getAPropertyWrite().getRhs() // one property down
27+
|
28+
succ = call
29+
)
30+
}
31+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/**
2+
* @name Unmodeled step
3+
* @description A potential step from an argument to a return that has no data/taint step.
4+
* @kind metric
5+
* @metricType project
6+
* @metricAggregate sum
7+
* @tags meta
8+
* @id js/meta/unmodeled-step
9+
*/
10+
11+
import javascript
12+
import meta.MetaMetrics
13+
private import Expressions.ExprHasNoEffect
14+
import meta.internal.TaintMetrics
15+
16+
predicate unmodeled(API::Node callee, API::CallNode call, DataFlow::Node pred, DataFlow::Node succ) {
17+
callee.getACall() = call and
18+
pred = call.getAnArgument() and
19+
succ = call and
20+
not inVoidContext(succ.asExpr()) and // void calls are irrelevant
21+
not call.getAnArgument() = relevantTaintSink() and // calls with sinks are considered modeled
22+
// we assume taint to the return value means the call is modeled
23+
not (
24+
TaintTracking::sharedTaintStep(_, succ)
25+
or
26+
DataFlow::SharedFlowStep::step(_, succ)
27+
or
28+
DataFlow::SharedFlowStep::step(_, succ, _, _)
29+
or
30+
DataFlow::SharedFlowStep::loadStep(_, succ, _)
31+
or
32+
DataFlow::SharedFlowStep::storeStep(_, succ, _)
33+
or
34+
DataFlow::SharedFlowStep::loadStoreStep(_, succ, _, _)
35+
or
36+
DataFlow::SharedFlowStep::loadStoreStep(_, succ, _)
37+
) and
38+
not pred.getFile() instanceof IgnoredFile and
39+
not succ.getFile() instanceof IgnoredFile
40+
}
41+
42+
select projectRoot(), count(DataFlow::Node pred, DataFlow::Node succ | unmodeled(_, _, pred, succ))

0 commit comments

Comments
 (0)