Skip to content

Commit 3bd6fd0

Browse files
committed
Swift: Update CleartextStorageDatabase to use DataFlow::ConfigSig
1 parent 21f9527 commit 3bd6fd0

File tree

2 files changed

+45
-4
lines changed

2 files changed

+45
-4
lines changed

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

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import codeql.swift.security.CleartextStorageDatabaseExtensions
1313
* A taint configuration from sensitive information to expressions that are
1414
* transmitted over a network.
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 }
@@ -48,3 +48,44 @@ class CleartextStorageConfig extends TaintTracking::Configuration {
4848
super.allowImplicitRead(node, c)
4949
}
5050
}
51+
52+
/**
53+
* A taint configuration from sensitive information to expressions that are
54+
* transmitted over a network.
55+
*/
56+
module CleartextStorageConfig implements DataFlow::ConfigSig {
57+
predicate isSource(DataFlow::Node node) { node.asExpr() instanceof SensitiveExpr }
58+
59+
predicate isSink(DataFlow::Node node) { node instanceof CleartextStorageDatabaseSink }
60+
61+
predicate isBarrier(DataFlow::Node sanitizer) {
62+
sanitizer instanceof CleartextStorageDatabaseSanitizer
63+
}
64+
65+
predicate isAdditionalFlowStep(DataFlow::Node nodeFrom, DataFlow::Node nodeTo) {
66+
any(CleartextStorageDatabaseAdditionalTaintStep s).step(nodeFrom, nodeTo)
67+
}
68+
69+
predicate isBarrierIn(DataFlow::Node node) {
70+
// make sources barriers so that we only report the closest instance
71+
isSource(node)
72+
}
73+
74+
predicate allowImplicitRead(DataFlow::Node node, DataFlow::ContentSet c) {
75+
// flow out from fields of an `NSManagedObject` or `RealmSwiftObject` at the sink,
76+
// for example in `realmObj.data = sensitive`.
77+
isSink(node) and
78+
exists(NominalTypeDecl d, Decl cx |
79+
d.getType().getABaseType*().getUnderlyingType().getName() =
80+
["NSManagedObject", "RealmSwiftObject"] and
81+
cx.asNominalTypeDecl() = d and
82+
c.getAReadContent().(DataFlow::Content::FieldContent).getField() = cx.getAMember()
83+
)
84+
}
85+
}
86+
87+
/**
88+
* Detect taint flow of sensitive information to expressions that are
89+
* transmitted over a network.
90+
*/
91+
module CleartextStorageFlow = TaintTracking::Global<CleartextStorageConfig>;

swift/ql/src/queries/Security/CWE-311/CleartextStorageDatabase.ql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import swift
1515
import codeql.swift.dataflow.DataFlow
1616
import codeql.swift.security.CleartextStorageDatabaseQuery
17-
import DataFlow::PathGraph
17+
import CleartextStorageFlow::PathGraph
1818

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

2929
from
30-
CleartextStorageConfig config, DataFlow::PathNode sourceNode, DataFlow::PathNode sinkNode,
30+
CleartextStorageFlow::PathNode sourceNode, CleartextStorageFlow::PathNode sinkNode,
3131
DataFlow::Node cleanSink
3232
where
33-
config.hasFlowPath(sourceNode, sinkNode) and
33+
CleartextStorageFlow::flowPath(sourceNode, sinkNode) and
3434
cleanSink = cleanupNode(sinkNode.getNode())
3535
select cleanSink, sourceNode, sinkNode,
3636
"This operation stores '" + cleanSink.toString() +

0 commit comments

Comments
 (0)