Skip to content

Commit 345e184

Browse files
committed
Swift: Add more test cases for swift/cleartext-transmission.
1 parent c0a69f1 commit 345e184

File tree

3 files changed

+79
-0
lines changed

3 files changed

+79
-0
lines changed

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

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,17 @@ edges
3232
| testURL.swift:105:19:105:53 | call to String.init(data:encoding:) | testURL.swift:106:20:106:20 | "..." | provenance | |
3333
| testURL.swift:105:19:105:53 | call to String.init(data:encoding:) [some:0] | testURL.swift:105:6:105:10 | let ...? [some:0] | provenance | |
3434
| testURL.swift:105:32:105:32 | data | testURL.swift:105:19:105:53 | call to String.init(data:encoding:) [some:0] | provenance | |
35+
| testURL.swift:116:52:116:52 | email | testURL.swift:116:18:116:18 | "..." | provenance | |
36+
| testURL.swift:117:28:117:28 | email | testURL.swift:117:18:117:18 | "..." | provenance | |
37+
| testURL.swift:118:53:118:53 | secret_key | testURL.swift:118:18:118:18 | "..." | provenance | |
38+
| testURL.swift:119:60:119:60 | email | testURL.swift:119:18:119:18 | "..." | provenance | |
39+
| testURL.swift:123:52:123:52 | phone_number | testURL.swift:123:18:123:18 | "..." | provenance | |
40+
| testURL.swift:124:25:124:25 | phone_number | testURL.swift:124:18:124:18 | "..." | provenance | |
41+
| testURL.swift:125:31:125:31 | phone_number | testURL.swift:125:18:125:18 | "..." | provenance | |
42+
| testURL.swift:126:28:126:28 | phone_number | testURL.swift:126:18:126:18 | "..." | provenance | |
43+
| testURL.swift:127:25:127:25 | phone_number | testURL.swift:127:18:127:18 | "..." | provenance | |
44+
| testURL.swift:131:37:131:37 | account_no | testURL.swift:131:18:131:18 | "..." | provenance | |
45+
| testURL.swift:132:39:132:39 | account_no | testURL.swift:132:18:132:18 | "..." | provenance | |
3546
nodes
3647
| file://:0:0:0:0 | .value | semmle.label | .value |
3748
| file://:0:0:0:0 | self | semmle.label | self |
@@ -90,6 +101,28 @@ nodes
90101
| testURL.swift:105:19:105:53 | call to String.init(data:encoding:) [some:0] | semmle.label | call to String.init(data:encoding:) [some:0] |
91102
| testURL.swift:105:32:105:32 | data | semmle.label | data |
92103
| testURL.swift:106:20:106:20 | "..." | semmle.label | "..." |
104+
| testURL.swift:116:18:116:18 | "..." | semmle.label | "..." |
105+
| testURL.swift:116:52:116:52 | email | semmle.label | email |
106+
| testURL.swift:117:18:117:18 | "..." | semmle.label | "..." |
107+
| testURL.swift:117:28:117:28 | email | semmle.label | email |
108+
| testURL.swift:118:18:118:18 | "..." | semmle.label | "..." |
109+
| testURL.swift:118:53:118:53 | secret_key | semmle.label | secret_key |
110+
| testURL.swift:119:18:119:18 | "..." | semmle.label | "..." |
111+
| testURL.swift:119:60:119:60 | email | semmle.label | email |
112+
| testURL.swift:123:18:123:18 | "..." | semmle.label | "..." |
113+
| testURL.swift:123:52:123:52 | phone_number | semmle.label | phone_number |
114+
| testURL.swift:124:18:124:18 | "..." | semmle.label | "..." |
115+
| testURL.swift:124:25:124:25 | phone_number | semmle.label | phone_number |
116+
| testURL.swift:125:18:125:18 | "..." | semmle.label | "..." |
117+
| testURL.swift:125:31:125:31 | phone_number | semmle.label | phone_number |
118+
| testURL.swift:126:18:126:18 | "..." | semmle.label | "..." |
119+
| testURL.swift:126:28:126:28 | phone_number | semmle.label | phone_number |
120+
| testURL.swift:127:18:127:18 | "..." | semmle.label | "..." |
121+
| testURL.swift:127:25:127:25 | phone_number | semmle.label | phone_number |
122+
| testURL.swift:131:18:131:18 | "..." | semmle.label | "..." |
123+
| testURL.swift:131:37:131:37 | account_no | semmle.label | account_no |
124+
| testURL.swift:132:18:132:18 | "..." | semmle.label | "..." |
125+
| testURL.swift:132:39:132:39 | account_no | semmle.label | account_no |
93126
subpaths
94127
| 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(_:) |
95128
| 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 |
@@ -121,3 +154,14 @@ subpaths
121154
| testURL.swift:75:18:75:69 | ... .+(_:_:) ... | testURL.swift:75:53:75:69 | call to get_cert_string() | testURL.swift:75:18:75:69 | ... .+(_:_:) ... | This operation transmits '... .+(_:_:) ...', which may contain unencrypted sensitive data from $@. | testURL.swift:75:53:75:69 | call to get_cert_string() | call to get_cert_string() |
122155
| testURL.swift:96:18:96:18 | "..." | testURL.swift:96:51:96:51 | certificate | testURL.swift:96:18:96:18 | "..." | This operation transmits '"..."', which may contain unencrypted sensitive data from $@. | testURL.swift:96:51:96:51 | certificate | certificate |
123156
| testURL.swift:106:20:106:20 | "..." | testURL.swift:104:16:104:57 | call to SecKeyCopyExternalRepresentation(_:_:) | testURL.swift:106:20:106:20 | "..." | This operation transmits '"..."', which may contain unencrypted sensitive data from $@. | testURL.swift:104:16:104:57 | call to SecKeyCopyExternalRepresentation(_:_:) | call to SecKeyCopyExternalRepresentation(_:_:) |
157+
| testURL.swift:116:18:116:18 | "..." | testURL.swift:116:52:116:52 | email | testURL.swift:116:18:116:18 | "..." | This operation transmits '"..."', which may contain unencrypted sensitive data from $@. | testURL.swift:116:52:116:52 | email | email |
158+
| testURL.swift:117:18:117:18 | "..." | testURL.swift:117:28:117:28 | email | testURL.swift:117:18:117:18 | "..." | This operation transmits '"..."', which may contain unencrypted sensitive data from $@. | testURL.swift:117:28:117:28 | email | email |
159+
| testURL.swift:118:18:118:18 | "..." | testURL.swift:118:53:118:53 | secret_key | testURL.swift:118:18:118:18 | "..." | This operation transmits '"..."', which may contain unencrypted sensitive data from $@. | testURL.swift:118:53:118:53 | secret_key | secret_key |
160+
| testURL.swift:119:18:119:18 | "..." | testURL.swift:119:60:119:60 | email | testURL.swift:119:18:119:18 | "..." | This operation transmits '"..."', which may contain unencrypted sensitive data from $@. | testURL.swift:119:60:119:60 | email | email |
161+
| testURL.swift:123:18:123:18 | "..." | testURL.swift:123:52:123:52 | phone_number | testURL.swift:123:18:123:18 | "..." | This operation transmits '"..."', which may contain unencrypted sensitive data from $@. | testURL.swift:123:52:123:52 | phone_number | phone_number |
162+
| testURL.swift:124:18:124:18 | "..." | testURL.swift:124:25:124:25 | phone_number | testURL.swift:124:18:124:18 | "..." | This operation transmits '"..."', which may contain unencrypted sensitive data from $@. | testURL.swift:124:25:124:25 | phone_number | phone_number |
163+
| testURL.swift:125:18:125:18 | "..." | testURL.swift:125:31:125:31 | phone_number | testURL.swift:125:18:125:18 | "..." | This operation transmits '"..."', which may contain unencrypted sensitive data from $@. | testURL.swift:125:31:125:31 | phone_number | phone_number |
164+
| testURL.swift:126:18:126:18 | "..." | testURL.swift:126:28:126:28 | phone_number | testURL.swift:126:18:126:18 | "..." | This operation transmits '"..."', which may contain unencrypted sensitive data from $@. | testURL.swift:126:28:126:28 | phone_number | phone_number |
165+
| testURL.swift:127:18:127:18 | "..." | testURL.swift:127:25:127:25 | phone_number | testURL.swift:127:18:127:18 | "..." | This operation transmits '"..."', which may contain unencrypted sensitive data from $@. | testURL.swift:127:25:127:25 | phone_number | phone_number |
166+
| testURL.swift:131:18:131:18 | "..." | testURL.swift:131:37:131:37 | account_no | testURL.swift:131:18:131:18 | "..." | This operation transmits '"..."', which may contain unencrypted sensitive data from $@. | testURL.swift:131:37:131:37 | account_no | account_no |
167+
| testURL.swift:132:18:132:18 | "..." | testURL.swift:132:39:132:39 | account_no | testURL.swift:132:18:132:18 | "..." | This operation transmits '"..."', which may contain unencrypted sensitive data from $@. | testURL.swift:132:39:132:39 | account_no | account_no |

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,3 +182,14 @@
182182
| testURL.swift:75:53:75:69 | call to get_cert_string() | label:get_cert_string, type:credential |
183183
| testURL.swift:96:51:96:51 | certificate | label:certificate, type:credential |
184184
| testURL.swift:104:16:104:57 | call to SecKeyCopyExternalRepresentation(_:_:) | label:password, type:password |
185+
| testURL.swift:116:52:116:52 | email | label:email, type:private information |
186+
| testURL.swift:117:28:117:28 | email | label:email, type:private information |
187+
| testURL.swift:118:53:118:53 | secret_key | label:secret_key, type:credential |
188+
| testURL.swift:119:60:119:60 | email | label:email, type:private information |
189+
| testURL.swift:123:52:123:52 | phone_number | label:phone_number, type:private information |
190+
| testURL.swift:124:25:124:25 | phone_number | label:phone_number, type:private information |
191+
| testURL.swift:125:31:125:31 | phone_number | label:phone_number, type:private information |
192+
| testURL.swift:126:28:126:28 | phone_number | label:phone_number, type:private information |
193+
| testURL.swift:127:25:127:25 | phone_number | label:phone_number, type:private information |
194+
| testURL.swift:131:37:131:37 | account_no | label:account_no, type:private information |
195+
| testURL.swift:132:39:132:39 | account_no | label:account_no, type:private information |

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,27 @@ func test4(key: SecKey) {
107107
}
108108
}
109109
}
110+
111+
func test5() {
112+
// variant URL types...
113+
let email = get_string()
114+
let secret_key = get_string()
115+
116+
_ = URL(string: "http://example.com/login?email=\(email)"); // BAD
117+
_ = URL(string: "mailto:\(email)"); // GOOD (revealing your e-amil address in an e-mail is expected) [FALSE POSITIVE]
118+
_ = URL(string: "mailto:[email protected]?subject=\(secret_key)"); // BAD
119+
_ = URL(string: "mailto:[email protected]?subject=foo&cc=\(email)"); // GOOD [FALSE POSITIVE]
120+
121+
let phone_number = get_string()
122+
123+
_ = URL(string: "http://example.com/profile?tel=\(phone_number)"); // BAD
124+
_ = URL(string: "tel:\(phone_number)") // GOOD [FALSE POSITIVE]
125+
_ = URL(string: "telprompt:\(phone_number)") // GOOD [FALSE POSITIVE]
126+
_ = URL(string: "callto:\(phone_number)") // GOOD [FALSE POSITIVE]
127+
_ = URL(string: "sms:\(phone_number)") // GOOD [FALSE POSITIVE]
128+
129+
let account_no = get_string()
130+
131+
_ = URL(string: "file:///foo/bar/\(account_no).csv") // GOOD (local, so not transmitted) [FALSE POSITIVE]
132+
_ = URL(string: "ftp://example.com/\(account_no).csv") // BAD
133+
}

0 commit comments

Comments
 (0)