Skip to content

Commit 80cd994

Browse files
committed
Swift: Add taint reach to SummaryStats.ql.
1 parent 2c50014 commit 80cd994

File tree

1 file changed

+30
-7
lines changed

1 file changed

+30
-7
lines changed

swift/ql/src/queries/Summary/SummaryStats.ql

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,42 @@
99
import swift
1010
import codeql.swift.dataflow.FlowSources
1111
import codeql.swift.security.SensitiveExprs
12+
import codeql.swift.dataflow.DataFlow
13+
import codeql.swift.dataflow.TaintTracking
1214

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()
1538
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()
1740
or
18-
what = "Local flow sources" and value = count(LocalFlowSource s)
41+
what = "Remote flow sources" and value = count(RemoteFlowSource s).toString()
1942
or
20-
what = "Remote flow sources" and value = count(RemoteFlowSource s)
43+
what = "Sensitive expressions" and value = count(SensitiveExpr e).toString()
2144
or
22-
what = "Sensitive expressions" and value = count(SensitiveExpr e)
45+
what = "Taint reach (per million nodes)" and value = taintReach().toString()
2346
}
2447

25-
from string what, int value
48+
from string what, string value
2649
where statistic(what, value)
2750
select what, value

0 commit comments

Comments
 (0)