@@ -15,21 +15,24 @@ import codeql.swift.dataflow.TaintTracking
15
15
/**
16
16
* A taint configuration for tainted data reaching any node.
17
17
*/
18
- class TaintReachConfig extends TaintTracking :: Configuration {
19
- TaintReachConfig ( ) { this = "TaintReachConfig" }
18
+ module TaintReachConfig implements DataFlow :: ConfigSig {
19
+ predicate isSource ( DataFlow :: Node node ) { node instanceof FlowSource }
20
20
21
- override predicate isSource ( DataFlow:: Node node ) { node instanceof FlowSource }
22
-
23
- override predicate isSink ( DataFlow:: Node node ) { any ( ) }
21
+ predicate isSink ( DataFlow:: Node node ) { any ( ) }
24
22
}
25
23
26
- float taintReach ( ) {
27
- exists ( TaintReachConfig config , int tainted , int total |
28
- tainted = count ( DataFlow:: Node n | config .hasFlowTo ( n ) ) and
29
- total = count ( DataFlow:: Node n ) and
30
- result = ( tainted * 1000000.0 ) / total
31
- )
32
- }
24
+ module TaintReachFlow = TaintTracking:: Make< TaintReachConfig > ;
25
+
26
+ /**
27
+ * Gets the total number of dataflow nodes that taint reaches (from any source).
28
+ */
29
+ int taintedNodesCount ( ) { result = count ( DataFlow:: Node n | TaintReachFlow:: hasFlowTo ( n ) ) }
30
+
31
+ /**
32
+ * Gets the proportion of dataflow nodes that taint reaches (from any source),
33
+ * expressed as a count per million nodes.
34
+ */
35
+ float taintReach ( ) { result = ( taintedNodesCount ( ) * 1000000.0 ) / count ( DataFlow:: Node n ) }
33
36
34
37
predicate statistic ( string what , string value ) {
35
38
what = "Files" and value = count ( File f ) .toString ( )
@@ -42,6 +45,10 @@ predicate statistic(string what, string value) {
42
45
or
43
46
what = "Sensitive expressions" and value = count ( SensitiveExpr e ) .toString ( )
44
47
or
48
+ what = "Dataflow nodes (total)" and value = count ( DataFlow:: Node n ) .toString ( )
49
+ or
50
+ what = "Dataflow nodes (tainted)" and value = taintedNodesCount ( ) .toString ( )
51
+ or
45
52
what = "Taint reach (per million nodes)" and value = taintReach ( ) .toString ( )
46
53
}
47
54
0 commit comments