Skip to content

Commit a5dd4a4

Browse files
committed
Swift: More tests of keys as sensitive data.
1 parent 6dd941e commit a5dd4a4

File tree

5 files changed

+143
-43
lines changed

5 files changed

+143
-43
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,8 @@ nodes
555555
| testCoreData.swift:95:15:95:15 | x | semmle.label | x |
556556
| testCoreData.swift:96:15:96:15 | y | semmle.label | y |
557557
| testCoreData.swift:97:15:97:15 | z | semmle.label | z |
558+
| testCoreData.swift:128:15:128:33 | call to generateSecretKey() | semmle.label | call to generateSecretKey() |
559+
| testCoreData.swift:129:15:129:30 | call to getCertificate() | semmle.label | call to getCertificate() |
558560
| testGRDB.swift:73:56:73:65 | [...] | semmle.label | [...] |
559561
| testGRDB.swift:73:56:73:65 | [...] [Collection element] | semmle.label | [...] [Collection element] |
560562
| testGRDB.swift:73:57:73:57 | password | semmle.label | password |
@@ -825,6 +827,8 @@ subpaths
825827
| testCoreData.swift:95:15:95:15 | x | testCoreData.swift:91:10:91:10 | passwd | testCoreData.swift:95:15:95:15 | x | This operation stores 'x' in a database. It may contain unencrypted sensitive data from $@. | testCoreData.swift:91:10:91:10 | passwd | passwd |
826828
| testCoreData.swift:96:15:96:15 | y | testCoreData.swift:92:10:92:10 | passwd | testCoreData.swift:96:15:96:15 | y | This operation stores 'y' in a database. It may contain unencrypted sensitive data from $@. | testCoreData.swift:92:10:92:10 | passwd | passwd |
827829
| 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 |
830+
| testCoreData.swift:128:15:128:33 | call to generateSecretKey() | testCoreData.swift:128:15:128:33 | call to generateSecretKey() | testCoreData.swift:128:15:128:33 | call to generateSecretKey() | This operation stores 'call to generateSecretKey()' in a database. It may contain unencrypted sensitive data from $@. | testCoreData.swift:128:15:128:33 | call to generateSecretKey() | call to generateSecretKey() |
831+
| testCoreData.swift:129:15:129:30 | call to getCertificate() | testCoreData.swift:129:15:129:30 | call to getCertificate() | testCoreData.swift:129:15:129:30 | call to getCertificate() | This operation stores 'call to getCertificate()' in a database. It may contain unencrypted sensitive data from $@. | testCoreData.swift:129:15:129:30 | call to getCertificate() | call to getCertificate() |
828832
| testGRDB.swift:73:56:73:65 | [...] | testGRDB.swift:73:57:73:57 | password | testGRDB.swift:73:56:73:65 | [...] | This operation stores '[...]' in a database. It may contain unencrypted sensitive data from $@. | testGRDB.swift:73:57:73:57 | password | password |
829833
| testGRDB.swift:76:42:76:51 | [...] | testGRDB.swift:76:43:76:43 | password | testGRDB.swift:76:42:76:51 | [...] | This operation stores '[...]' in a database. It may contain unencrypted sensitive data from $@. | testGRDB.swift:76:43:76:43 | password | password |
830834
| testGRDB.swift:81:44:81:53 | [...] | testGRDB.swift:81:45:81:45 | password | testGRDB.swift:81:44:81:53 | [...] | This operation stores '[...]' in a database. It may contain unencrypted sensitive data from $@. | testGRDB.swift:81:45:81:45 | password | password |

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

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,15 @@ edges
1414
| testSend.swift:86:7:86:7 | self | file://:0:0:0:0 | self |
1515
| testSend.swift:94:27:94:30 | .password | testSend.swift:86:7:86:7 | self |
1616
| testSend.swift:94:27:94:30 | .password | testSend.swift:94:27:94:39 | .value |
17-
| testURL.swift:17:54:17:54 | passwd | testURL.swift:17:22:17:54 | ... .+(_:_:) ... |
18-
| testURL.swift:19:55:19:55 | account_no | testURL.swift:19:22:19:55 | ... .+(_:_:) ... |
19-
| testURL.swift:20:55:20:55 | credit_card_no | testURL.swift:20:22:20:55 | ... .+(_:_:) ... |
20-
| testURL.swift:28:55:28:55 | e_mail | testURL.swift:28:22:28:55 | ... .+(_:_:) ... |
21-
| testURL.swift:30:57:30:57 | a_homeaddr_z | testURL.swift:30:22:30:57 | ... .+(_:_:) ... |
22-
| testURL.swift:32:55:32:55 | resident_ID | testURL.swift:32:22:32:55 | ... .+(_:_:) ... |
17+
| testURL.swift:17:50:17:50 | passwd | testURL.swift:17:18:17:50 | ... .+(_:_:) ... |
18+
| testURL.swift:19:51:19:51 | account_no | testURL.swift:19:18:19:51 | ... .+(_:_:) ... |
19+
| testURL.swift:20:51:20:51 | credit_card_no | testURL.swift:20:18:20:51 | ... .+(_:_:) ... |
20+
| testURL.swift:28:51:28:51 | e_mail | testURL.swift:28:18:28:51 | ... .+(_:_:) ... |
21+
| testURL.swift:30:53:30:53 | a_homeaddr_z | testURL.swift:30:18:30:53 | ... .+(_:_:) ... |
22+
| testURL.swift:32:51:32:51 | resident_ID | testURL.swift:32:18:32:51 | ... .+(_:_:) ... |
23+
| testURL.swift:51:52:51:67 | call to get_secret_key() | testURL.swift:51:18:51:67 | ... .+(_:_:) ... |
24+
| testURL.swift:53:53:53:69 | call to get_cert_string() | testURL.swift:53:18:53:69 | ... .+(_:_:) ... |
25+
| testURL.swift:74:51:74:51 | certificate | testURL.swift:74:18:74:18 | "..." |
2326
nodes
2427
| file://:0:0:0:0 | .value | semmle.label | .value |
2528
| file://:0:0:0:0 | self | semmle.label | self |
@@ -52,19 +55,25 @@ nodes
5255
| testSend.swift:86:7:86:7 | self | semmle.label | self |
5356
| testSend.swift:94:27:94:30 | .password | semmle.label | .password |
5457
| testSend.swift:94:27:94:39 | .value | semmle.label | .value |
55-
| testURL.swift:17:22:17:54 | ... .+(_:_:) ... | semmle.label | ... .+(_:_:) ... |
56-
| testURL.swift:17:54:17:54 | passwd | semmle.label | passwd |
57-
| testURL.swift:19:22:19:55 | ... .+(_:_:) ... | semmle.label | ... .+(_:_:) ... |
58-
| testURL.swift:19:55:19:55 | account_no | semmle.label | account_no |
59-
| testURL.swift:20:22:20:55 | ... .+(_:_:) ... | semmle.label | ... .+(_:_:) ... |
60-
| testURL.swift:20:55:20:55 | credit_card_no | semmle.label | credit_card_no |
58+
| testURL.swift:17:18:17:50 | ... .+(_:_:) ... | semmle.label | ... .+(_:_:) ... |
59+
| testURL.swift:17:50:17:50 | passwd | semmle.label | passwd |
60+
| testURL.swift:19:18:19:51 | ... .+(_:_:) ... | semmle.label | ... .+(_:_:) ... |
61+
| testURL.swift:19:51:19:51 | account_no | semmle.label | account_no |
62+
| testURL.swift:20:18:20:51 | ... .+(_:_:) ... | semmle.label | ... .+(_:_:) ... |
63+
| testURL.swift:20:51:20:51 | credit_card_no | semmle.label | credit_card_no |
6164
| testURL.swift:24:22:24:22 | passwd | semmle.label | passwd |
62-
| testURL.swift:28:22:28:55 | ... .+(_:_:) ... | semmle.label | ... .+(_:_:) ... |
63-
| testURL.swift:28:55:28:55 | e_mail | semmle.label | e_mail |
64-
| testURL.swift:30:22:30:57 | ... .+(_:_:) ... | semmle.label | ... .+(_:_:) ... |
65-
| testURL.swift:30:57:30:57 | a_homeaddr_z | semmle.label | a_homeaddr_z |
66-
| testURL.swift:32:22:32:55 | ... .+(_:_:) ... | semmle.label | ... .+(_:_:) ... |
67-
| testURL.swift:32:55:32:55 | resident_ID | semmle.label | resident_ID |
65+
| testURL.swift:28:18:28:51 | ... .+(_:_:) ... | semmle.label | ... .+(_:_:) ... |
66+
| testURL.swift:28:51:28:51 | e_mail | semmle.label | e_mail |
67+
| testURL.swift:30:18:30:53 | ... .+(_:_:) ... | semmle.label | ... .+(_:_:) ... |
68+
| testURL.swift:30:53:30:53 | a_homeaddr_z | semmle.label | a_homeaddr_z |
69+
| testURL.swift:32:18:32:51 | ... .+(_:_:) ... | semmle.label | ... .+(_:_:) ... |
70+
| testURL.swift:32:51:32:51 | resident_ID | semmle.label | resident_ID |
71+
| testURL.swift:51:18:51:67 | ... .+(_:_:) ... | semmle.label | ... .+(_:_:) ... |
72+
| testURL.swift:51:52:51:67 | call to get_secret_key() | semmle.label | call to get_secret_key() |
73+
| testURL.swift:53:18:53:69 | ... .+(_:_:) ... | semmle.label | ... .+(_:_:) ... |
74+
| testURL.swift:53:53:53:69 | call to get_cert_string() | semmle.label | call to get_cert_string() |
75+
| testURL.swift:74:18:74:18 | "..." | semmle.label | "..." |
76+
| testURL.swift:74:51:74:51 | certificate | semmle.label | certificate |
6877
subpaths
6978
| testSend.swift:60:17:60:17 | password | testSend.swift:41:10:41:18 | data | testSend.swift:41:45:41:45 | data | testSend.swift:60:13:60:25 | call to pad(_:) |
7079
| testSend.swift:94:27:94:30 | .password | testSend.swift:86:7:86:7 | self | file://:0:0:0:0 | .value | testSend.swift:94:27:94:39 | .value |
@@ -85,10 +94,13 @@ subpaths
8594
| testSend.swift:79:27:79:30 | .BankCardNo | testSend.swift:79:27:79:30 | .BankCardNo | testSend.swift:79:27:79:30 | .BankCardNo | This operation transmits '.BankCardNo', which may contain unencrypted sensitive data from $@. | testSend.swift:79:27:79:30 | .BankCardNo | .BankCardNo |
8695
| testSend.swift:80:27:80:30 | .MyCreditRating | testSend.swift:80:27:80:30 | .MyCreditRating | testSend.swift:80:27:80:30 | .MyCreditRating | This operation transmits '.MyCreditRating', which may contain unencrypted sensitive data from $@. | testSend.swift:80:27:80:30 | .MyCreditRating | .MyCreditRating |
8796
| testSend.swift:94:27:94:39 | .value | testSend.swift:94:27:94:30 | .password | testSend.swift:94:27:94:39 | .value | This operation transmits '.value', which may contain unencrypted sensitive data from $@. | testSend.swift:94:27:94:30 | .password | .password |
88-
| testURL.swift:17:22:17:54 | ... .+(_:_:) ... | testURL.swift:17:54:17:54 | passwd | testURL.swift:17:22:17:54 | ... .+(_:_:) ... | This operation transmits '... .+(_:_:) ...', which may contain unencrypted sensitive data from $@. | testURL.swift:17:54:17:54 | passwd | passwd |
89-
| testURL.swift:19:22:19:55 | ... .+(_:_:) ... | testURL.swift:19:55:19:55 | account_no | testURL.swift:19:22:19:55 | ... .+(_:_:) ... | This operation transmits '... .+(_:_:) ...', which may contain unencrypted sensitive data from $@. | testURL.swift:19:55:19:55 | account_no | account_no |
90-
| testURL.swift:20:22:20:55 | ... .+(_:_:) ... | testURL.swift:20:55:20:55 | credit_card_no | testURL.swift:20:22:20:55 | ... .+(_:_:) ... | This operation transmits '... .+(_:_:) ...', which may contain unencrypted sensitive data from $@. | testURL.swift:20:55:20:55 | credit_card_no | credit_card_no |
97+
| testURL.swift:17:18:17:50 | ... .+(_:_:) ... | testURL.swift:17:50:17:50 | passwd | testURL.swift:17:18:17:50 | ... .+(_:_:) ... | This operation transmits '... .+(_:_:) ...', which may contain unencrypted sensitive data from $@. | testURL.swift:17:50:17:50 | passwd | passwd |
98+
| testURL.swift:19:18:19:51 | ... .+(_:_:) ... | testURL.swift:19:51:19:51 | account_no | testURL.swift:19:18:19:51 | ... .+(_:_:) ... | This operation transmits '... .+(_:_:) ...', which may contain unencrypted sensitive data from $@. | testURL.swift:19:51:19:51 | account_no | account_no |
99+
| testURL.swift:20:18:20:51 | ... .+(_:_:) ... | testURL.swift:20:51:20:51 | credit_card_no | testURL.swift:20:18:20:51 | ... .+(_:_:) ... | This operation transmits '... .+(_:_:) ...', which may contain unencrypted sensitive data from $@. | testURL.swift:20:51:20:51 | credit_card_no | credit_card_no |
91100
| testURL.swift:24:22:24:22 | passwd | testURL.swift:24:22:24:22 | passwd | testURL.swift:24:22:24:22 | passwd | This operation transmits 'passwd', which may contain unencrypted sensitive data from $@. | testURL.swift:24:22:24:22 | passwd | passwd |
92-
| testURL.swift:28:22:28:55 | ... .+(_:_:) ... | testURL.swift:28:55:28:55 | e_mail | testURL.swift:28:22:28:55 | ... .+(_:_:) ... | This operation transmits '... .+(_:_:) ...', which may contain unencrypted sensitive data from $@. | testURL.swift:28:55:28:55 | e_mail | e_mail |
93-
| testURL.swift:30:22:30:57 | ... .+(_:_:) ... | testURL.swift:30:57:30:57 | a_homeaddr_z | testURL.swift:30:22:30:57 | ... .+(_:_:) ... | This operation transmits '... .+(_:_:) ...', which may contain unencrypted sensitive data from $@. | testURL.swift:30:57:30:57 | a_homeaddr_z | a_homeaddr_z |
94-
| testURL.swift:32:22:32:55 | ... .+(_:_:) ... | testURL.swift:32:55:32:55 | resident_ID | testURL.swift:32:22:32:55 | ... .+(_:_:) ... | This operation transmits '... .+(_:_:) ...', which may contain unencrypted sensitive data from $@. | testURL.swift:32:55:32:55 | resident_ID | resident_ID |
101+
| testURL.swift:28:18:28:51 | ... .+(_:_:) ... | testURL.swift:28:51:28:51 | e_mail | testURL.swift:28:18:28:51 | ... .+(_:_:) ... | This operation transmits '... .+(_:_:) ...', which may contain unencrypted sensitive data from $@. | testURL.swift:28:51:28:51 | e_mail | e_mail |
102+
| testURL.swift:30:18:30:53 | ... .+(_:_:) ... | testURL.swift:30:53:30:53 | a_homeaddr_z | testURL.swift:30:18:30:53 | ... .+(_:_:) ... | This operation transmits '... .+(_:_:) ...', which may contain unencrypted sensitive data from $@. | testURL.swift:30:53:30:53 | a_homeaddr_z | a_homeaddr_z |
103+
| testURL.swift:32:18:32:51 | ... .+(_:_:) ... | testURL.swift:32:51:32:51 | resident_ID | testURL.swift:32:18:32:51 | ... .+(_:_:) ... | This operation transmits '... .+(_:_:) ...', which may contain unencrypted sensitive data from $@. | testURL.swift:32:51:32:51 | resident_ID | resident_ID |
104+
| testURL.swift:51:18:51:67 | ... .+(_:_:) ... | testURL.swift:51:52:51:67 | call to get_secret_key() | testURL.swift:51:18:51:67 | ... .+(_:_:) ... | This operation transmits '... .+(_:_:) ...', which may contain unencrypted sensitive data from $@. | testURL.swift:51:52:51:67 | call to get_secret_key() | call to get_secret_key() |
105+
| testURL.swift:53:18:53:69 | ... .+(_:_:) ... | testURL.swift:53:53:53:69 | call to get_cert_string() | testURL.swift:53:18:53:69 | ... .+(_:_:) ... | This operation transmits '... .+(_:_:) ...', which may contain unencrypted sensitive data from $@. | testURL.swift:53:53:53:69 | call to get_cert_string() | call to get_cert_string() |
106+
| testURL.swift:74:18:74:18 | "..." | testURL.swift:74:51:74:51 | certificate | testURL.swift:74:18:74:18 | "..." | This operation transmits '"..."', which may contain unencrypted sensitive data from $@. | testURL.swift:74:51:74:51 | certificate | certificate |

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@
8787
| testCoreData.swift:91:10:91:10 | passwd | label:passwd, type:credential |
8888
| testCoreData.swift:92:10:92:10 | passwd | label:passwd, type:credential |
8989
| testCoreData.swift:93:10:93:10 | passwd | label:passwd, type:credential |
90+
| testCoreData.swift:128:15:128:33 | call to generateSecretKey() | label:generateSecretKey, type:credential |
91+
| testCoreData.swift:129:15:129:30 | call to getCertificate() | label:getCertificate, type:credential |
9092
| testGRDB.swift:73:57:73:57 | password | label:password, type:credential |
9193
| testGRDB.swift:76:43:76:43 | password | label:password, type:credential |
9294
| testGRDB.swift:81:45:81:45 | password | label:password, type:credential |
@@ -163,10 +165,13 @@
163165
| testSend.swift:79:27:79:30 | .BankCardNo | label:BankCardNo, type:private information |
164166
| testSend.swift:80:27:80:30 | .MyCreditRating | label:MyCreditRating, type:private information |
165167
| testSend.swift:94:27:94:30 | .password | label:password, type:credential |
166-
| testURL.swift:17:54:17:54 | passwd | label:passwd, type:credential |
167-
| testURL.swift:19:55:19:55 | account_no | label:account_no, type:private information |
168-
| testURL.swift:20:55:20:55 | credit_card_no | label:credit_card_no, type:private information |
168+
| testURL.swift:17:50:17:50 | passwd | label:passwd, type:credential |
169+
| testURL.swift:19:51:19:51 | account_no | label:account_no, type:private information |
170+
| testURL.swift:20:51:20:51 | credit_card_no | label:credit_card_no, type:private information |
169171
| testURL.swift:24:22:24:22 | passwd | label:passwd, type:credential |
170-
| testURL.swift:28:55:28:55 | e_mail | label:e_mail, type:private information |
171-
| testURL.swift:30:57:30:57 | a_homeaddr_z | label:a_homeaddr_z, type:private information |
172-
| testURL.swift:32:55:32:55 | resident_ID | label:resident_ID, type:private information |
172+
| testURL.swift:28:51:28:51 | e_mail | label:e_mail, type:private information |
173+
| testURL.swift:30:53:30:53 | a_homeaddr_z | label:a_homeaddr_z, type:private information |
174+
| testURL.swift:32:51:32:51 | resident_ID | label:resident_ID, type:private information |
175+
| testURL.swift:51:52:51:67 | call to get_secret_key() | label:get_secret_key, type:credential |
176+
| testURL.swift:53:53:53:69 | call to get_cert_string() | label:get_cert_string, type:credential |
177+
| testURL.swift:74:51:74:51 | certificate | label:certificate, type:credential |

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

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,10 @@ func test3(obj : NSManagedObject, x : String) {
7777
doSomething(password: x);
7878
obj.setValue(x, forKey: "myKey") // BAD
7979

80-
var y = getPassword();
80+
let y = getPassword();
8181
obj.setValue(y, forKey: "myKey") // BAD
8282

83-
var z = MyClass()
83+
let z = MyClass()
8484
obj.setValue(z.harmless, forKey: "myKey") // GOOD (not sensitive)
8585
obj.setValue(z.password, forKey: "myKey") // BAD
8686
}
@@ -104,3 +104,36 @@ func test4(obj : NSManagedObject, passwd : String) {
104104
obj.setValue(y, forKey: "myKey") // GOOD (not sensitive)
105105
obj.setValue(z, forKey: "myKey") // GOOD (not sensitive)
106106
}
107+
108+
func createSecureKey() -> String { return "" }
109+
func generateSecretKey() -> String { return "" }
110+
func getCertificate() -> String { return "" }
111+
112+
class KeyGen {
113+
func generate() -> String { return "" }
114+
}
115+
116+
class KeyManager {
117+
func generateKey() -> String { return "" }
118+
}
119+
120+
class SecureKeyStore {
121+
func getEncryptionKey() -> String { return "" }
122+
}
123+
124+
func test5(obj : NSManagedObject) {
125+
// more variants...
126+
127+
obj.setValue(createSecureKey(), forKey: "myKey") // BAD [NOT DETECTED]
128+
obj.setValue(generateSecretKey(), forKey: "myKey") // BAD
129+
obj.setValue(getCertificate(), forKey: "myKey") // BAD
130+
131+
let gen = KeyGen()
132+
let v = gen.generate()
133+
134+
obj.setValue(KeyGen().generate(), forKey: "myKey") // BAD [NOT DETECTED]
135+
obj.setValue(gen.generate(), forKey: "myKey") // BAD [NOT DETECTED]
136+
obj.setValue(v, forKey: "myKey") // BAD [NOT DETECTED]
137+
obj.setValue(KeyManager().generateKey(), forKey: "myKey") // BAD [NOT DETECTED]
138+
obj.setValue(SecureKeyStore().getEncryptionKey(), forKey: "myKey") // BAD [NOT DETECTED]
139+
}

0 commit comments

Comments
 (0)