|
9 | 9 | import swift
|
10 | 10 | import codeql.swift.dataflow.FlowSources
|
11 | 11 | import codeql.swift.security.SensitiveExprs
|
| 12 | +import codeql.swift.dataflow.DataFlow |
| 13 | +import codeql.swift.dataflow.TaintTracking |
12 | 14 |
|
13 |
| -predicate statistic(string what, int value) { |
14 |
| - what = "Files" and value = count(File f) |
| 15 | +/** |
| 16 | + * A taint configuration for tainted data reaching any node. |
| 17 | + */ |
| 18 | +class TaintReachConfig extends TaintTracking::Configuration { |
| 19 | + TaintReachConfig() { this = "TaintReachConfig" } |
| 20 | + |
| 21 | + override predicate isSource(DataFlow::Node node) { node instanceof FlowSource } |
| 22 | + |
| 23 | + override predicate isSink(DataFlow::Node node) { any() } |
| 24 | +} |
| 25 | + |
| 26 | +float taintReach() { |
| 27 | + exists(TaintReachConfig config, int tainted, int total | |
| 28 | + tainted = count(DataFlow::Node n | config.hasFlow(_, n)) and |
| 29 | + total = count(DataFlow::Node n) and |
| 30 | + result = (tainted * 1000000.0) / total |
| 31 | + ) |
| 32 | +} |
| 33 | + |
| 34 | +predicate statistic(string what, string value) { |
| 35 | + what = "Files" and value = count(File f).toString() |
| 36 | + or |
| 37 | + what = "Expressions" and value = count(Expr e | not e.getFile() instanceof UnknownFile).toString() |
15 | 38 | or
|
16 |
| - what = "Expressions" and value = count(Expr e | not e.getFile() instanceof UnknownFile) |
| 39 | + what = "Local flow sources" and value = count(LocalFlowSource s).toString() |
17 | 40 | or
|
18 |
| - what = "Local flow sources" and value = count(LocalFlowSource s) |
| 41 | + what = "Remote flow sources" and value = count(RemoteFlowSource s).toString() |
19 | 42 | or
|
20 |
| - what = "Remote flow sources" and value = count(RemoteFlowSource s) |
| 43 | + what = "Sensitive expressions" and value = count(SensitiveExpr e).toString() |
21 | 44 | or
|
22 |
| - what = "Sensitive expressions" and value = count(SensitiveExpr e) |
| 45 | + what = "Taint reach (per million nodes)" and value = taintReach().toString() |
23 | 46 | }
|
24 | 47 |
|
25 |
| -from string what, int value |
| 48 | +from string what, string value |
26 | 49 | where statistic(what, value)
|
27 | 50 | select what, value
|
0 commit comments