Skip to content

Commit e8bfb87

Browse files
committed
Swift: Rewrite CleartextStoragePreferences to use DataFlow::ConfigSig
1 parent a45f381 commit e8bfb87

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

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

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import codeql.swift.security.CleartextStoragePreferencesExtensions
1313
* A taint configuration from sensitive information to expressions that are
1414
* stored as preferences.
1515
*/
16-
class CleartextStorageConfig extends TaintTracking::Configuration {
16+
deprecated class CleartextStorageConfig extends TaintTracking::Configuration {
1717
CleartextStorageConfig() { this = "CleartextStorageConfig" }
1818

1919
override predicate isSource(DataFlow::Node node) { node.asExpr() instanceof SensitiveExpr }
@@ -33,3 +33,32 @@ class CleartextStorageConfig extends TaintTracking::Configuration {
3333
this.isSource(node)
3434
}
3535
}
36+
37+
/**
38+
* A taint configuration from sensitive information to expressions that are
39+
* stored as preferences.
40+
*/
41+
module CleartextStorageConfig implements DataFlow::ConfigSig {
42+
predicate isSource(DataFlow::Node node) { node.asExpr() instanceof SensitiveExpr }
43+
44+
predicate isSink(DataFlow::Node node) { node instanceof CleartextStoragePreferencesSink }
45+
46+
predicate isBarrier(DataFlow::Node sanitizer) {
47+
sanitizer instanceof CleartextStoragePreferencesSanitizer
48+
}
49+
50+
predicate isAdditionalFlowStep(DataFlow::Node nodeFrom, DataFlow::Node nodeTo) {
51+
any(CleartextStoragePreferencesAdditionalTaintStep s).step(nodeFrom, nodeTo)
52+
}
53+
54+
predicate isBarrierIn(DataFlow::Node node) {
55+
// make sources barriers so that we only report the closest instance
56+
isSource(node)
57+
}
58+
}
59+
60+
/**
61+
* Detect taint flow of sensitive information to expressions that are stored
62+
* as preferences.
63+
*/
64+
module CleartextStorageFlow = TaintTracking::Global<CleartextStorageConfig>;

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import swift
1414
import codeql.swift.dataflow.DataFlow
1515
import codeql.swift.security.CleartextStoragePreferencesQuery
16-
import DataFlow::PathGraph
16+
import CleartextStorageFlow::PathGraph
1717

1818
/**
1919
* Gets a prettier node to use in the results.
@@ -26,10 +26,10 @@ DataFlow::Node cleanupNode(DataFlow::Node n) {
2626
}
2727

2828
from
29-
CleartextStorageConfig config, DataFlow::PathNode sourceNode, DataFlow::PathNode sinkNode,
29+
CleartextStorageFlow::PathNode sourceNode, CleartextStorageFlow::PathNode sinkNode,
3030
DataFlow::Node cleanSink
3131
where
32-
config.hasFlowPath(sourceNode, sinkNode) and
32+
CleartextStorageFlow::flowPath(sourceNode, sinkNode) and
3333
cleanSink = cleanupNode(sinkNode.getNode())
3434
select cleanSink, sourceNode, sinkNode,
3535
"This operation stores '" + cleanSink.toString() + "' in " +

0 commit comments

Comments
 (0)