-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathTaintReach.qll
More file actions
48 lines (41 loc) · 1.65 KB
/
TaintReach.qll
File metadata and controls
48 lines (41 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/**
* Taint reach computation. Taint reach is the proportion of all dataflow nodes that can be reached
* via taint flow from any active thread model source. It's usually expressed per million nodes.
*/
import rust
private import codeql.rust.Concepts
private import codeql.rust.dataflow.DataFlow
private import codeql.rust.dataflow.TaintTracking
private import codeql.rust.dataflow.internal.Node
/**
* A taint configuration for taint reach (flow to any node from any modeled source).
*/
private module TaintReachConfig implements DataFlow::ConfigSig {
predicate isSource(DataFlow::Node node) { node instanceof ActiveThreatModelSource }
predicate isSink(DataFlow::Node node) { any() }
}
private module TaintReachFlow = TaintTracking::Global<TaintReachConfig>;
/**
* Gets the total number of data flow nodes that taint reaches (from any source).
*
* We don't include flow summary nodes, as their number is unstable (varies when models
* are added).
*/
int getTaintedNodesCount() {
result = count(DataFlow::Node n | TaintReachFlow::flowTo(n) and not n instanceof FlowSummaryNode)
}
/**
* Gets the total number of data flow nodes.
*
* We don't include flow summary nodes, as their number is unstable (varies when models
* are added).
*/
int getTotalNodesCount() { result = count(DataFlow::Node n | not n instanceof FlowSummaryNode) }
/**
* Gets the proportion of data flow nodes that taint reaches (from any source),
* expressed as a count per million nodes.
*
* We don't include flow summary nodes, as their number is unstable (varies when models
* are added).
*/
float getTaintReach() { result = (getTaintedNodesCount() * 1000000.0) / getTotalNodesCount() }