Skip to content

Commit 3c55cdd

Browse files
committed
Swift: Catch the last two test results as well.
1 parent d42848b commit 3c55cdd

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

swift/ql/src/queries/Security/CWE-321/HardcodedEncryptionKey.ql

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class EncryptionKeySink extends Expr {
5353
c.getFullName() = ["RNCryptor", "RNEncryptor", "RNDecryptor"] and
5454
c.getAMember() = f and
5555
call.getStaticTarget() = f and
56-
call.getArgumentWithLabel("encryptionKey").getExpr() = this
56+
call.getArgumentWithLabel(["encryptionKey", "withEncryptionKey"]).getExpr() = this
5757
)
5858
}
5959
}

swift/ql/test/query-tests/Security/CWE-321/HardcodedEncryptionKey.expected

+6
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ edges
1010
| rncryptor.swift:60:19:60:38 | call to Data.init(_:) : | rncryptor.swift:73:102:73:102 | myConstKey |
1111
| rncryptor.swift:60:19:60:38 | call to Data.init(_:) : | rncryptor.swift:75:37:75:37 | myConstKey |
1212
| rncryptor.swift:60:19:60:38 | call to Data.init(_:) : | rncryptor.swift:76:37:76:37 | myConstKey |
13+
| rncryptor.swift:60:19:60:38 | call to Data.init(_:) : | rncryptor.swift:78:66:78:66 | myConstKey |
14+
| rncryptor.swift:60:19:60:38 | call to Data.init(_:) : | rncryptor.swift:79:66:79:66 | myConstKey |
1315
| rncryptor.swift:60:19:60:38 | call to Data.init(_:) : | rncryptor.swift:80:94:80:94 | myConstKey |
1416
| rncryptor.swift:60:19:60:38 | call to Data.init(_:) : | rncryptor.swift:81:102:81:102 | myConstKey |
1517
| rncryptor.swift:60:24:60:24 | abcdef123456 : | rncryptor.swift:5:5:5:29 | [summary param] 0 in Data.init(_:) : |
@@ -49,6 +51,8 @@ nodes
4951
| rncryptor.swift:73:102:73:102 | myConstKey | semmle.label | myConstKey |
5052
| rncryptor.swift:75:37:75:37 | myConstKey | semmle.label | myConstKey |
5153
| rncryptor.swift:76:37:76:37 | myConstKey | semmle.label | myConstKey |
54+
| rncryptor.swift:78:66:78:66 | myConstKey | semmle.label | myConstKey |
55+
| rncryptor.swift:79:66:79:66 | myConstKey | semmle.label | myConstKey |
5256
| rncryptor.swift:80:94:80:94 | myConstKey | semmle.label | myConstKey |
5357
| rncryptor.swift:81:102:81:102 | myConstKey | semmle.label | myConstKey |
5458
| test.swift:76:3:76:3 | this string is constant : | semmle.label | this string is constant : |
@@ -86,6 +90,8 @@ subpaths
8690
| rncryptor.swift:73:102:73:102 | myConstKey | rncryptor.swift:60:24:60:24 | abcdef123456 : | rncryptor.swift:73:102:73:102 | myConstKey | The key 'myConstKey' has been initialized with hard-coded values from $@. | rncryptor.swift:60:24:60:24 | abcdef123456 : | abcdef123456 |
8791
| rncryptor.swift:75:37:75:37 | myConstKey | rncryptor.swift:60:24:60:24 | abcdef123456 : | rncryptor.swift:75:37:75:37 | myConstKey | The key 'myConstKey' has been initialized with hard-coded values from $@. | rncryptor.swift:60:24:60:24 | abcdef123456 : | abcdef123456 |
8892
| rncryptor.swift:76:37:76:37 | myConstKey | rncryptor.swift:60:24:60:24 | abcdef123456 : | rncryptor.swift:76:37:76:37 | myConstKey | The key 'myConstKey' has been initialized with hard-coded values from $@. | rncryptor.swift:60:24:60:24 | abcdef123456 : | abcdef123456 |
93+
| rncryptor.swift:78:66:78:66 | myConstKey | rncryptor.swift:60:24:60:24 | abcdef123456 : | rncryptor.swift:78:66:78:66 | myConstKey | The key 'myConstKey' has been initialized with hard-coded values from $@. | rncryptor.swift:60:24:60:24 | abcdef123456 : | abcdef123456 |
94+
| rncryptor.swift:79:66:79:66 | myConstKey | rncryptor.swift:60:24:60:24 | abcdef123456 : | rncryptor.swift:79:66:79:66 | myConstKey | The key 'myConstKey' has been initialized with hard-coded values from $@. | rncryptor.swift:60:24:60:24 | abcdef123456 : | abcdef123456 |
8995
| rncryptor.swift:80:94:80:94 | myConstKey | rncryptor.swift:60:24:60:24 | abcdef123456 : | rncryptor.swift:80:94:80:94 | myConstKey | The key 'myConstKey' has been initialized with hard-coded values from $@. | rncryptor.swift:60:24:60:24 | abcdef123456 : | abcdef123456 |
9096
| rncryptor.swift:81:102:81:102 | myConstKey | rncryptor.swift:60:24:60:24 | abcdef123456 : | rncryptor.swift:81:102:81:102 | myConstKey | The key 'myConstKey' has been initialized with hard-coded values from $@. | rncryptor.swift:60:24:60:24 | abcdef123456 : | abcdef123456 |
9197
| test.swift:108:21:108:21 | keyString | test.swift:76:3:76:3 | this string is constant : | test.swift:108:21:108:21 | keyString | The key 'keyString' has been initialized with hard-coded values from $@. | test.swift:76:3:76:3 | this string is constant : | this string is constant |

swift/ql/test/query-tests/Security/CWE-321/rncryptor.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ func test(cond: Bool) {
7575
let _ = RNDecryptor(encryptionKey: myConstKey, hmacKey: myHMACKey, handler: myHandler) // BAD
7676
let _ = RNDecryptor(encryptionKey: myConstKey, HMACKey: myHMACKey, handler: myHandler) // BAD
7777

78-
let _ = try? myDecryptor.decryptData(myData, withEncryptionKey: myConstKey, hmacKey: myHMACKey) // BAD [NOT DETECTED]
79-
let _ = try? myDecryptor.decryptData(myData, withEncryptionKey: myConstKey, HMACKey: myHMACKey) // BAD [NOT DETECTED]
78+
let _ = try? myDecryptor.decryptData(myData, withEncryptionKey: myConstKey, hmacKey: myHMACKey) // BAD
79+
let _ = try? myDecryptor.decryptData(myData, withEncryptionKey: myConstKey, HMACKey: myHMACKey) // BAD
8080
let _ = try? myDecryptor.decryptData(myData, with: kRNCryptorAES256Settings, encryptionKey: myConstKey, hmacKey: myHMACKey) // BAD
8181
let _ = try? myDecryptor.decryptData(myData, withSettings: kRNCryptorAES256Settings, encryptionKey: myConstKey, HMACKey: myHMACKey) // BAD
8282
}

0 commit comments

Comments
 (0)