Skip to content

Commit aa5820c

Browse files
committed
Swift: Add some test cases.
1 parent e038f60 commit aa5820c

File tree

4 files changed

+43
-0
lines changed

4 files changed

+43
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@
133133
| testSend.swift:78:27:78:30 | .CarePlanID | label:CarePlanID, type:private information |
134134
| testSend.swift:79:27:79:30 | .BankCardNo | label:BankCardNo, type:private information |
135135
| testSend.swift:80:27:80:30 | .MyCreditRating | label:MyCreditRating, type:private information |
136+
| testSend.swift:94:27:94:30 | .password | label:password, type:credential |
136137
| testURL.swift:17:54:17:54 | passwd | label:passwd, type:credential |
137138
| testURL.swift:19:55:19:55 | account_no | label:account_no, type:private information |
138139
| testURL.swift:20:55:20:55 | credit_card_no | label:credit_card_no, type:private information |

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,17 @@ func test2(password : String, license_key: String, ms: MyStruct, connection : NW
8080
connection.send(content: ms.MyCreditRating, completion: .idempotent) // BAD
8181
connection.send(content: ms.OneTimeCode, completion: .idempotent) // BAD [NOT DETECTED]
8282
}
83+
84+
struct MyOuter {
85+
struct MyInner {
86+
var value: String
87+
}
88+
89+
var password: MyInner
90+
var harmless: MyInner
91+
}
92+
93+
func test3(mo : MyOuter, connection : NWConnection) {
94+
connection.send(content: mo.password.value, completion: .idempotent) // BAD [NOT DETECTED]
95+
connection.send(content: mo.harmless.value, completion: .idempotent) // GOOD
96+
}

swift/ql/test/query-tests/Security/CWE-312/cleartextLoggingTest.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,3 +159,17 @@ func test3(x: String) {
159159
NSLog(z.harmless) // Safe
160160
NSLog(z.password) // $ hasCleartextLogging=160
161161
}
162+
163+
struct MyOuter {
164+
struct MyInner {
165+
var value: String
166+
}
167+
168+
var password: MyInner
169+
var harmless: MyInner
170+
}
171+
172+
func test3(mo : MyOuter) {
173+
NSLog(mo.password.value) // BAD [NOT DETECTED]
174+
NSLog(mo.harmless.value) // GOOD
175+
}

swift/ql/test/query-tests/Security/CWE-312/testUserDefaults.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,17 @@ func test4(passwd: String) {
6868
UserDefaults.standard.set(y, forKey: "myKey") // GOOD (not sensitive)
6969
UserDefaults.standard.set(z, forKey: "myKey") // GOOD (not sensitive)
7070
}
71+
72+
struct MyOuter {
73+
struct MyInner {
74+
var value: String
75+
}
76+
77+
var password: MyInner
78+
var harmless: MyInner
79+
}
80+
81+
func test5(mo : MyOuter) {
82+
UserDefaults.standard.set(mo.password.value, forKey: "myKey") // BAD [NOT DETECTED]
83+
UserDefaults.standard.set(mo.harmless.value, forKey: "myKey") // GOOD
84+
}

0 commit comments

Comments
 (0)