Skip to content

Commit a45f381

Browse files
committed
Swift: Rewrite CleartextLogging to use DataFlow::ConfigSig
1 parent 5deafea commit a45f381

File tree

3 files changed

+29
-9
lines changed

3 files changed

+29
-9
lines changed

swift/ql/lib/codeql/swift/security/CleartextLoggingQuery.qll

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ private import codeql.swift.security.SensitiveExprs
1212
/**
1313
* A taint-tracking configuration for cleartext logging of sensitive data vulnerabilities.
1414
*/
15-
class CleartextLoggingConfiguration extends TaintTracking::Configuration {
15+
deprecated class CleartextLoggingConfiguration extends TaintTracking::Configuration {
1616
CleartextLoggingConfiguration() { this = "CleartextLoggingConfiguration" }
1717

1818
override predicate isSource(DataFlow::Node source) { source.asExpr() instanceof SensitiveExpr }
@@ -30,3 +30,26 @@ class CleartextLoggingConfiguration extends TaintTracking::Configuration {
3030
any(CleartextLoggingAdditionalTaintStep s).step(n1, n2)
3131
}
3232
}
33+
34+
/**
35+
* A taint-tracking configuration for cleartext logging of sensitive data vulnerabilities.
36+
*/
37+
module CleartextLoggingConfig implements DataFlow::ConfigSig {
38+
predicate isSource(DataFlow::Node source) { source.asExpr() instanceof SensitiveExpr }
39+
40+
predicate isSink(DataFlow::Node sink) { sink instanceof CleartextLoggingSink }
41+
42+
predicate isBarrier(DataFlow::Node sanitizer) { sanitizer instanceof CleartextLoggingSanitizer }
43+
44+
// Disregard paths that contain other paths. This helps with performance.
45+
predicate isBarrierIn(DataFlow::Node node) { isSource(node) }
46+
47+
predicate isAdditionalFlowStep(DataFlow::Node n1, DataFlow::Node n2) {
48+
any(CleartextLoggingAdditionalTaintStep s).step(n1, n2)
49+
}
50+
}
51+
52+
/**
53+
* Detect taint flow of cleartext logging of sensitive data vulnerabilities.
54+
*/
55+
module CleartextLoggingFlow = TaintTracking::Global<CleartextLoggingConfig>;

swift/ql/src/queries/Security/CWE-312/CleartextLogging.ql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
import swift
1717
import codeql.swift.dataflow.DataFlow
1818
import codeql.swift.security.CleartextLoggingQuery
19-
import DataFlow::PathGraph
19+
import CleartextLoggingFlow::PathGraph
2020

21-
from DataFlow::PathNode src, DataFlow::PathNode sink
22-
where any(CleartextLoggingConfiguration c).hasFlowPath(src, sink)
21+
from CleartextLoggingFlow::PathNode src, CleartextLoggingFlow::PathNode sink
22+
where CleartextLoggingFlow::flowPath(src, sink)
2323
select sink.getNode(), src, sink, "This $@ is written to a log file.", src.getNode(),
2424
"potentially sensitive information"

swift/ql/test/query-tests/Security/CWE-312/CleartextLoggingTest.ql

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,8 @@ class CleartextLogging extends InlineExpectationsTest {
99
override string getARelevantTag() { result = "hasCleartextLogging" }
1010

1111
override predicate hasActualResult(Location location, string element, string tag, string value) {
12-
exists(
13-
CleartextLoggingConfiguration config, DataFlow::Node source, DataFlow::Node sink,
14-
Expr sinkExpr
15-
|
16-
config.hasFlow(source, sink) and
12+
exists(DataFlow::Node source, DataFlow::Node sink, Expr sinkExpr |
13+
CleartextLoggingFlow::flow(source, sink) and
1714
sinkExpr = sink.asExpr() and
1815
location = sinkExpr.getLocation() and
1916
element = sinkExpr.toString() and

0 commit comments

Comments
 (0)