Skip to content

Commit 2690732

Browse files
committed
Swift: Special cases to get taint flow working.
1 parent 698a9e2 commit 2690732

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,22 @@ class CleartextStorageConfig extends TaintTracking::Configuration {
8282
// make sources barriers so that we only report the closest instance
8383
isSource(node)
8484
}
85+
86+
override predicate isAdditionalTaintStep(DataFlow::Node node1, DataFlow::Node node2) {
87+
// TODO: the following special case flows are required to catch any of the Realm test
88+
// cases, I hope we'll be able to remove them once we have field flow???
89+
// flow out from field accesses, i.e. `a.b` -> `a`
90+
exists(MemberRefExpr m |
91+
node1.asExpr() = m and // `a.b`
92+
node2.asExpr() = m.getBaseExpr() // `a`
93+
)
94+
or
95+
// flow through assignment (!)
96+
exists(AssignExpr ae |
97+
node1.asExpr() = ae.getSource() and
98+
node2.asExpr() = ae.getDest()
99+
)
100+
}
85101
}
86102

87103
from CleartextStorageConfig config, DataFlow::PathNode sourceNode, DataFlow::PathNode sinkNode

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ edges
1818
| testCoreData.swift:100:13:100:14 | &... : | testCoreData.swift:38:11:38:23 | WriteDef : |
1919
| testCoreData.swift:100:13:100:14 | &... : | testCoreData.swift:38:11:38:23 | data : |
2020
| testCoreData.swift:100:13:100:14 | &... : | testCoreData.swift:100:7:100:14 | data: &... : |
21+
| testRealm.swift:34:11:34:11 | myPassword : | testRealm.swift:35:12:35:12 | a |
22+
| testRealm.swift:42:11:42:11 | myPassword : | testRealm.swift:43:47:43:47 | c |
2123
nodes
2224
| testCoreData.swift:37:14:37:22 | WriteDef : | semmle.label | WriteDef : |
2325
| testCoreData.swift:37:14:37:22 | WriteDef : | semmle.label | data : |
@@ -49,6 +51,10 @@ nodes
4951
| testCoreData.swift:100:13:100:14 | &... : | semmle.label | &... : |
5052
| testCoreData.swift:103:15:103:15 | x | semmle.label | x |
5153
| testCoreData.swift:104:15:104:15 | y | semmle.label | y |
54+
| testRealm.swift:34:11:34:11 | myPassword : | semmle.label | myPassword : |
55+
| testRealm.swift:35:12:35:12 | a | semmle.label | a |
56+
| testRealm.swift:42:11:42:11 | myPassword : | semmle.label | myPassword : |
57+
| testRealm.swift:43:47:43:47 | c | semmle.label | c |
5258
subpaths
5359
| testCoreData.swift:99:14:99:14 | x : | testCoreData.swift:37:14:37:22 | WriteDef : | testCoreData.swift:37:49:37:49 | data : | testCoreData.swift:99:6:99:15 | call to encrypt(_:) : |
5460
| 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(_:) : |
@@ -66,3 +72,5 @@ subpaths
6672
| testCoreData.swift:97:15:97:15 | z | testCoreData.swift:93:10:93:10 | passwd : | testCoreData.swift:97:15:97:15 | z | This operation stores 'z' in a database. It may contain unencrypted sensitive data from $@ | testCoreData.swift:93:10:93:10 | passwd : | passwd |
6773
| testCoreData.swift:103:15:103:15 | x | testCoreData.swift:91:10:91:10 | passwd : | testCoreData.swift:103:15:103:15 | x | This operation stores 'x' in a database. It may contain unencrypted sensitive data from $@ | testCoreData.swift:91:10:91:10 | passwd : | passwd |
6874
| testCoreData.swift:104:15:104:15 | y | testCoreData.swift:92:10:92:10 | passwd : | testCoreData.swift:104:15:104:15 | y | This operation stores 'y' in a database. It may contain unencrypted sensitive data from $@ | testCoreData.swift:92:10:92:10 | passwd : | passwd |
75+
| testRealm.swift:35:12:35:12 | a | testRealm.swift:34:11:34:11 | myPassword : | testRealm.swift:35:12:35:12 | a | This operation stores 'a' in a database. It may contain unencrypted sensitive data from $@ | testRealm.swift:34:11:34:11 | myPassword : | myPassword |
76+
| testRealm.swift:43:47:43:47 | c | testRealm.swift:42:11:42:11 | myPassword : | testRealm.swift:43:47:43:47 | c | This operation stores 'c' in a database. It may contain unencrypted sensitive data from $@ | testRealm.swift:42:11:42:11 | myPassword : | myPassword |

swift/ql/test/query-tests/Security/CWE-311/testRealm.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func test1(realm : Realm, myPassword : String, myHashedPassword : String) {
4949
// retrieve objects ...
5050

5151
var e = realm.object(ofType: MyRealmSwiftObject.self, forPrimaryKey: "key")
52-
e!.data = myPassword // BAD
52+
e!.data = myPassword // BAD [NOT DETECTED]
5353

5454
var f = realm.object(ofType: MyRealmSwiftObject.self, forPrimaryKey: "key")
5555
f!.data = myHashedPassword // GOOD (not sensitive)

0 commit comments

Comments
 (0)