Skip to content

Commit bb6aa11

Browse files
committed
Swift: Additional test case.
1 parent ca50f11 commit bb6aa11

File tree

2 files changed

+43
-20
lines changed

2 files changed

+43
-20
lines changed

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

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,19 @@ edges
2424
| file://:0:0:0:0 | value : | file://:0:0:0:0 | [post] self [encryptionKey] : |
2525
| misc.swift:5:5:5:29 | [summary param] 0 in Data.init(_:) : | file://:0:0:0:0 | [summary] to write: return (return) in Data.init(_:) : |
2626
| misc.swift:30:7:30:7 | value : | file://:0:0:0:0 | value : |
27-
| misc.swift:38:19:38:38 | call to Data.init(_:) : | misc.swift:41:41:41:41 | myConstKey |
28-
| misc.swift:38:19:38:38 | call to Data.init(_:) : | misc.swift:45:25:45:25 | myConstKey : |
29-
| misc.swift:38:24:38:24 | abcdef123456 : | misc.swift:5:5:5:29 | [summary param] 0 in Data.init(_:) : |
30-
| misc.swift:38:24:38:24 | abcdef123456 : | misc.swift:38:19:38:38 | call to Data.init(_:) : |
31-
| misc.swift:45:2:45:2 | [post] config [encryptionKey] : | misc.swift:45:2:45:2 | [post] config |
32-
| misc.swift:45:25:45:25 | myConstKey : | misc.swift:30:7:30:7 | value : |
33-
| misc.swift:45:25:45:25 | myConstKey : | misc.swift:45:2:45:2 | [post] config |
34-
| misc.swift:45:25:45:25 | myConstKey : | misc.swift:45:2:45:2 | [post] config [encryptionKey] : |
27+
| misc.swift:46:19:46:38 | call to Data.init(_:) : | misc.swift:49:41:49:41 | myConstKey |
28+
| misc.swift:46:19:46:38 | call to Data.init(_:) : | misc.swift:53:25:53:25 | myConstKey : |
29+
| misc.swift:46:19:46:38 | call to Data.init(_:) : | misc.swift:57:41:57:41 | myConstKey : |
30+
| misc.swift:46:24:46:24 | abcdef123456 : | misc.swift:5:5:5:29 | [summary param] 0 in Data.init(_:) : |
31+
| misc.swift:46:24:46:24 | abcdef123456 : | misc.swift:46:19:46:38 | call to Data.init(_:) : |
32+
| misc.swift:53:2:53:2 | [post] config [encryptionKey] : | misc.swift:53:2:53:2 | [post] config |
33+
| misc.swift:53:25:53:25 | myConstKey : | misc.swift:30:7:30:7 | value : |
34+
| misc.swift:53:25:53:25 | myConstKey : | misc.swift:53:2:53:2 | [post] config |
35+
| misc.swift:53:25:53:25 | myConstKey : | misc.swift:53:2:53:2 | [post] config [encryptionKey] : |
36+
| misc.swift:57:2:57:18 | [post] getter for .config [encryptionKey] : | misc.swift:57:2:57:18 | [post] getter for .config |
37+
| misc.swift:57:41:57:41 | myConstKey : | misc.swift:30:7:30:7 | value : |
38+
| misc.swift:57:41:57:41 | myConstKey : | misc.swift:57:2:57:18 | [post] getter for .config |
39+
| misc.swift:57:41:57:41 | myConstKey : | misc.swift:57:2:57:18 | [post] getter for .config [encryptionKey] : |
3540
| rncryptor.swift:5:5:5:29 | [summary param] 0 in Data.init(_:) : | file://:0:0:0:0 | [summary] to write: return (return) in Data.init(_:) : |
3641
| rncryptor.swift:60:19:60:38 | call to Data.init(_:) : | rncryptor.swift:65:73:65:73 | myConstKey |
3742
| rncryptor.swift:60:19:60:38 | call to Data.init(_:) : | rncryptor.swift:66:73:66:73 | myConstKey |
@@ -81,12 +86,15 @@ nodes
8186
| file://:0:0:0:0 | value : | semmle.label | value : |
8287
| misc.swift:5:5:5:29 | [summary param] 0 in Data.init(_:) : | semmle.label | [summary param] 0 in Data.init(_:) : |
8388
| misc.swift:30:7:30:7 | value : | semmle.label | value : |
84-
| misc.swift:38:19:38:38 | call to Data.init(_:) : | semmle.label | call to Data.init(_:) : |
85-
| misc.swift:38:24:38:24 | abcdef123456 : | semmle.label | abcdef123456 : |
86-
| misc.swift:41:41:41:41 | myConstKey | semmle.label | myConstKey |
87-
| misc.swift:45:2:45:2 | [post] config | semmle.label | [post] config |
88-
| misc.swift:45:2:45:2 | [post] config [encryptionKey] : | semmle.label | [post] config [encryptionKey] : |
89-
| misc.swift:45:25:45:25 | myConstKey : | semmle.label | myConstKey : |
89+
| misc.swift:46:19:46:38 | call to Data.init(_:) : | semmle.label | call to Data.init(_:) : |
90+
| misc.swift:46:24:46:24 | abcdef123456 : | semmle.label | abcdef123456 : |
91+
| misc.swift:49:41:49:41 | myConstKey | semmle.label | myConstKey |
92+
| misc.swift:53:2:53:2 | [post] config | semmle.label | [post] config |
93+
| misc.swift:53:2:53:2 | [post] config [encryptionKey] : | semmle.label | [post] config [encryptionKey] : |
94+
| misc.swift:53:25:53:25 | myConstKey : | semmle.label | myConstKey : |
95+
| misc.swift:57:2:57:18 | [post] getter for .config | semmle.label | [post] getter for .config |
96+
| misc.swift:57:2:57:18 | [post] getter for .config [encryptionKey] : | semmle.label | [post] getter for .config [encryptionKey] : |
97+
| misc.swift:57:41:57:41 | myConstKey : | semmle.label | myConstKey : |
9098
| rncryptor.swift:5:5:5:29 | [summary param] 0 in Data.init(_:) : | semmle.label | [summary param] 0 in Data.init(_:) : |
9199
| rncryptor.swift:60:19:60:38 | call to Data.init(_:) : | semmle.label | call to Data.init(_:) : |
92100
| rncryptor.swift:60:24:60:24 | abcdef123456 : | semmle.label | abcdef123456 : |
@@ -106,9 +114,11 @@ nodes
106114
| rncryptor.swift:81:102:81:102 | myConstKey | semmle.label | myConstKey |
107115
| rncryptor.swift:83:92:83:92 | myConstKey | semmle.label | myConstKey |
108116
subpaths
109-
| misc.swift:38:24:38:24 | abcdef123456 : | misc.swift:5:5:5:29 | [summary param] 0 in Data.init(_:) : | file://:0:0:0:0 | [summary] to write: return (return) in Data.init(_:) : | misc.swift:38:19:38:38 | call to Data.init(_:) : |
110-
| misc.swift:45:25:45:25 | myConstKey : | misc.swift:30:7:30:7 | value : | file://:0:0:0:0 | [post] self : | misc.swift:45:2:45:2 | [post] config |
111-
| misc.swift:45:25:45:25 | myConstKey : | misc.swift:30:7:30:7 | value : | file://:0:0:0:0 | [post] self [encryptionKey] : | misc.swift:45:2:45:2 | [post] config [encryptionKey] : |
117+
| misc.swift:46:24:46:24 | abcdef123456 : | misc.swift:5:5:5:29 | [summary param] 0 in Data.init(_:) : | file://:0:0:0:0 | [summary] to write: return (return) in Data.init(_:) : | misc.swift:46:19:46:38 | call to Data.init(_:) : |
118+
| misc.swift:53:25:53:25 | myConstKey : | misc.swift:30:7:30:7 | value : | file://:0:0:0:0 | [post] self : | misc.swift:53:2:53:2 | [post] config |
119+
| misc.swift:53:25:53:25 | myConstKey : | misc.swift:30:7:30:7 | value : | file://:0:0:0:0 | [post] self [encryptionKey] : | misc.swift:53:2:53:2 | [post] config [encryptionKey] : |
120+
| misc.swift:57:41:57:41 | myConstKey : | misc.swift:30:7:30:7 | value : | file://:0:0:0:0 | [post] self : | misc.swift:57:2:57:18 | [post] getter for .config |
121+
| misc.swift:57:41:57:41 | myConstKey : | misc.swift:30:7:30:7 | value : | file://:0:0:0:0 | [post] self [encryptionKey] : | misc.swift:57:2:57:18 | [post] getter for .config [encryptionKey] : |
112122
| rncryptor.swift:60:24:60:24 | abcdef123456 : | rncryptor.swift:5:5:5:29 | [summary param] 0 in Data.init(_:) : | file://:0:0:0:0 | [summary] to write: return (return) in Data.init(_:) : | rncryptor.swift:60:19:60:38 | call to Data.init(_:) : |
113123
#select
114124
| cryptoswift.swift:108:21:108:21 | keyString | cryptoswift.swift:76:3:76:3 | this string is constant : | cryptoswift.swift:108:21:108:21 | keyString | The key 'keyString' has been initialized with hard-coded values from $@. | cryptoswift.swift:76:3:76:3 | this string is constant : | this string is constant |
@@ -130,9 +140,10 @@ subpaths
130140
| cryptoswift.swift:162:24:162:24 | keyString | cryptoswift.swift:76:3:76:3 | this string is constant : | cryptoswift.swift:162:24:162:24 | keyString | The key 'keyString' has been initialized with hard-coded values from $@. | cryptoswift.swift:76:3:76:3 | this string is constant : | this string is constant |
131141
| cryptoswift.swift:163:24:163:24 | key | cryptoswift.swift:90:26:90:121 | [...] : | cryptoswift.swift:163:24:163:24 | key | The key 'key' has been initialized with hard-coded values from $@. | cryptoswift.swift:90:26:90:121 | [...] : | [...] |
132142
| cryptoswift.swift:164:24:164:24 | keyString | cryptoswift.swift:76:3:76:3 | this string is constant : | cryptoswift.swift:164:24:164:24 | keyString | The key 'keyString' has been initialized with hard-coded values from $@. | cryptoswift.swift:76:3:76:3 | this string is constant : | this string is constant |
133-
| file://:0:0:0:0 | [post] self | misc.swift:38:24:38:24 | abcdef123456 : | file://:0:0:0:0 | [post] self | The key '[post] self' has been initialized with hard-coded values from $@. | misc.swift:38:24:38:24 | abcdef123456 : | abcdef123456 |
134-
| misc.swift:41:41:41:41 | myConstKey | misc.swift:38:24:38:24 | abcdef123456 : | misc.swift:41:41:41:41 | myConstKey | The key 'myConstKey' has been initialized with hard-coded values from $@. | misc.swift:38:24:38:24 | abcdef123456 : | abcdef123456 |
135-
| misc.swift:45:2:45:2 | [post] config | misc.swift:38:24:38:24 | abcdef123456 : | misc.swift:45:2:45:2 | [post] config | The key '[post] config' has been initialized with hard-coded values from $@. | misc.swift:38:24:38:24 | abcdef123456 : | abcdef123456 |
143+
| file://:0:0:0:0 | [post] self | misc.swift:46:24:46:24 | abcdef123456 : | file://:0:0:0:0 | [post] self | The key '[post] self' has been initialized with hard-coded values from $@. | misc.swift:46:24:46:24 | abcdef123456 : | abcdef123456 |
144+
| misc.swift:49:41:49:41 | myConstKey | misc.swift:46:24:46:24 | abcdef123456 : | misc.swift:49:41:49:41 | myConstKey | The key 'myConstKey' has been initialized with hard-coded values from $@. | misc.swift:46:24:46:24 | abcdef123456 : | abcdef123456 |
145+
| misc.swift:53:2:53:2 | [post] config | misc.swift:46:24:46:24 | abcdef123456 : | misc.swift:53:2:53:2 | [post] config | The key '[post] config' has been initialized with hard-coded values from $@. | misc.swift:46:24:46:24 | abcdef123456 : | abcdef123456 |
146+
| misc.swift:57:2:57:18 | [post] getter for .config | misc.swift:46:24:46:24 | abcdef123456 : | misc.swift:57:2:57:18 | [post] getter for .config | The key '[post] getter for .config' has been initialized with hard-coded values from $@. | misc.swift:46:24:46:24 | abcdef123456 : | abcdef123456 |
136147
| rncryptor.swift:65:73:65:73 | myConstKey | rncryptor.swift:60:24:60:24 | abcdef123456 : | rncryptor.swift:65:73:65:73 | myConstKey | The key 'myConstKey' has been initialized with hard-coded values from $@. | rncryptor.swift:60:24:60:24 | abcdef123456 : | abcdef123456 |
137148
| rncryptor.swift:66:73:66:73 | myConstKey | rncryptor.swift:60:24:60:24 | abcdef123456 : | rncryptor.swift:66:73:66:73 | myConstKey | The key 'myConstKey' has been initialized with hard-coded values from $@. | rncryptor.swift:60:24:60:24 | abcdef123456 : | abcdef123456 |
138149
| rncryptor.swift:67:73:67:73 | myConstKey | rncryptor.swift:60:24:60:24 | abcdef123456 : | rncryptor.swift:67:73:67:73 | myConstKey | The key 'myConstKey' has been initialized with hard-coded values from $@. | rncryptor.swift:60:24:60:24 | abcdef123456 : | abcdef123456 |

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ extension Realm {
3333

3434
// --- tests ---
3535

36+
class ConfigContainer {
37+
init() {
38+
config = Realm.Configuration()
39+
}
40+
41+
var config: Realm.Configuration
42+
}
43+
3644
func test(myVarStr: String) {
3745
let myVarKey = Data(myVarStr)
3846
let myConstKey = Data("abcdef123456")
@@ -43,4 +51,8 @@ func test(myVarStr: String) {
4351
var config = Realm.Configuration() // GOOD
4452
config.encryptionKey = myVarKey // GOOD
4553
config.encryptionKey = myConstKey // BAD
54+
55+
var configContainer = ConfigContainer()
56+
configContainer.config.encryptionKey = myVarKey // GOOD
57+
configContainer.config.encryptionKey = myConstKey // BAD
4658
}

0 commit comments

Comments
 (0)