Skip to content

Commit 129ed42

Browse files
committed
Swift: Use allowImplicitRead as a better solution replacing one of the special flow cases.
1 parent c0bc0d7 commit 129ed42

File tree

2 files changed

+28
-14
lines changed

2 files changed

+28
-14
lines changed

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

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,16 +84,21 @@ class CleartextStorageConfig extends TaintTracking::Configuration {
8484
isSource(node)
8585
}
8686

87-
override predicate isAdditionalTaintStep(DataFlow::Node node1, DataFlow::Node node2) {
88-
// TODO: the following special case flows are required to catch any of the Realm test
89-
// cases, I hope we'll be able to remove them once we have field flow???
90-
// flow out from field accesses, i.e. `a.b` -> `a`
91-
exists(MemberRefExpr m |
92-
node1.asExpr() = m and // `a.b`
93-
node2.asExpr() = m.getImmediateBase() // `a`
87+
override predicate allowImplicitRead(DataFlow::Node node, DataFlow::ContentSet c) {
88+
// flow out from fields of a `RealmSwiftObject` at the sink, for example in `obj.var = tainted; sink(obj)`.
89+
isSink(node) and
90+
exists(ClassDecl cd |
91+
c.getAReadContent().(DataFlow::Content::FieldContent).getField() = cd.getAMember() and
92+
cd.getName() = ["RealmSwiftObject", "MyRealmSwiftObject"]
93+
// TODO: should be cd.getParent*().getName() = "RealmSwiftObject"
9494
)
9595
or
96-
// flow through assignment (!)
96+
// any default implicit reads
97+
super.allowImplicitRead(node, c)
98+
}
99+
100+
override predicate isAdditionalTaintStep(DataFlow::Node node1, DataFlow::Node node2) {
101+
// flow through assignment (!) TODO: we really shouldn't need this as a special case
97102
exists(AssignExpr ae |
98103
node1.asExpr() = ae.getSource() and
99104
node2.asExpr() = ae.getDest()

swift/ql/test/query-tests/Security/CWE-311/CleartextStorageDatabase.expected

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
edges
2+
| file://:0:0:0:0 | value : | file://:0:0:0:0 | [post] self [data] : |
23
| testCoreData.swift:18:19:18:26 | value : | testCoreData.swift:19:12:19:12 | value |
34
| testCoreData.swift:31:3:31:3 | newValue : | testCoreData.swift:32:13:32:13 | newValue |
45
| testCoreData.swift:37:14:37:22 | data : | testCoreData.swift:37:49:37:49 | data : |
@@ -19,11 +20,16 @@ edges
1920
| testCoreData.swift:100:13:100:14 | &... : | testCoreData.swift:38:11:38:23 | data : |
2021
| testCoreData.swift:100:13:100:14 | &... : | testCoreData.swift:100:13:100:14 | [post] &... : |
2122
| testCoreData.swift:100:13:100:14 | [post] &... : | testCoreData.swift:104:15:104:15 | y |
22-
| testRealm.swift:34:2:34:2 | a : | testRealm.swift:35:12:35:12 | a |
23-
| testRealm.swift:34:11:34:11 | myPassword : | testRealm.swift:34:2:34:2 | a : |
24-
| testRealm.swift:42:2:42:2 | c : | testRealm.swift:43:47:43:47 | c |
25-
| testRealm.swift:42:11:42:11 | myPassword : | testRealm.swift:42:2:42:2 | c : |
23+
| testRealm.swift:16:6:16:6 | value : | file://:0:0:0:0 | value : |
24+
| testRealm.swift:34:2:34:2 | [post] a [data] : | testRealm.swift:35:12:35:12 | a |
25+
| testRealm.swift:34:11:34:11 | myPassword : | testRealm.swift:16:6:16:6 | value : |
26+
| testRealm.swift:34:11:34:11 | myPassword : | testRealm.swift:34:2:34:2 | [post] a [data] : |
27+
| testRealm.swift:42:2:42:2 | [post] c [data] : | testRealm.swift:43:47:43:47 | c |
28+
| testRealm.swift:42:11:42:11 | myPassword : | testRealm.swift:16:6:16:6 | value : |
29+
| testRealm.swift:42:11:42:11 | myPassword : | testRealm.swift:42:2:42:2 | [post] c [data] : |
2630
nodes
31+
| file://:0:0:0:0 | [post] self [data] : | semmle.label | [post] self [data] : |
32+
| file://:0:0:0:0 | value : | semmle.label | value : |
2733
| testCoreData.swift:18:19:18:26 | value : | semmle.label | value : |
2834
| testCoreData.swift:19:12:19:12 | value | semmle.label | value |
2935
| testCoreData.swift:31:3:31:3 | newValue : | semmle.label | newValue : |
@@ -54,15 +60,18 @@ nodes
5460
| testCoreData.swift:100:13:100:14 | [post] &... : | semmle.label | [post] &... : |
5561
| testCoreData.swift:103:15:103:15 | x | semmle.label | x |
5662
| testCoreData.swift:104:15:104:15 | y | semmle.label | y |
57-
| testRealm.swift:34:2:34:2 | a : | semmle.label | a : |
63+
| testRealm.swift:16:6:16:6 | value : | semmle.label | value : |
64+
| testRealm.swift:34:2:34:2 | [post] a [data] : | semmle.label | [post] a [data] : |
5865
| testRealm.swift:34:11:34:11 | myPassword : | semmle.label | myPassword : |
5966
| testRealm.swift:35:12:35:12 | a | semmle.label | a |
60-
| testRealm.swift:42:2:42:2 | c : | semmle.label | c : |
67+
| testRealm.swift:42:2:42:2 | [post] c [data] : | semmle.label | [post] c [data] : |
6168
| testRealm.swift:42:11:42:11 | myPassword : | semmle.label | myPassword : |
6269
| testRealm.swift:43:47:43:47 | c | semmle.label | c |
6370
subpaths
6471
| testCoreData.swift:99:14:99:14 | x : | testCoreData.swift:37:14:37:22 | data : | testCoreData.swift:37:49:37:49 | data : | testCoreData.swift:99:6:99:15 | call to encrypt(_:) : |
6572
| testCoreData.swift:100:13:100:14 | &... : | testCoreData.swift:38:11:38:23 | data : | testCoreData.swift:38:1:38:33 | data[return] : | testCoreData.swift:100:13:100:14 | [post] &... : |
73+
| testRealm.swift:34:11:34:11 | myPassword : | testRealm.swift:16:6:16:6 | value : | file://:0:0:0:0 | [post] self [data] : | testRealm.swift:34:2:34:2 | [post] a [data] : |
74+
| testRealm.swift:42:11:42:11 | myPassword : | testRealm.swift:16:6:16:6 | value : | file://:0:0:0:0 | [post] self [data] : | testRealm.swift:42:2:42:2 | [post] c [data] : |
6675
#select
6776
| testCoreData.swift:19:12:19:12 | value | testCoreData.swift:61:25:61:25 | password : | testCoreData.swift:19:12:19:12 | value | This operation stores 'value' in a database. It may contain unencrypted sensitive data from $@ | testCoreData.swift:61:25:61:25 | password : | password |
6877
| testCoreData.swift:32:13:32:13 | newValue | testCoreData.swift:64:16:64:16 | password : | testCoreData.swift:32:13:32:13 | newValue | This operation stores 'newValue' in a database. It may contain unencrypted sensitive data from $@ | testCoreData.swift:64:16:64:16 | password : | password |

0 commit comments

Comments
 (0)