Skip to content

Commit 691665f

Browse files
committed
Swift: Add models for SQLite.swift.
1 parent bece2e8 commit 691665f

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

swift/ql/lib/codeql/swift/security/HardcodedEncryptionKeyExtensions.qll

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ private class EncryptionKeySinks extends SinkModelCsv {
7676
";;false;sqlite3_rekey(_:_:_:);;;Argument[1];encryption-key",
7777
";;false;sqlite3_key_v2(_:_:_:_:);;;Argument[2];encryption-key",
7878
";;false;sqlite3_rekey_v2(_:_:_:_:);;;Argument[2];encryption-key",
79+
// SQLite.swift
80+
";Connection;true;key(_:db:);;;Argument[0];encryption-key",
81+
";Connection;true;keyAndMigrate(_:db:);;;Argument[0];encryption-key",
82+
";Connection;true;rekey(_:db:);;;Argument[0];encryption-key",
83+
";Connection;true;sqlcipher_export(_:key:);;;Argument[1];encryption-key",
7984
]
8085
}
8186
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ edges
5252
| rncryptor.swift:60:19:60:38 | call to Data.init(_:) | rncryptor.swift:83:92:83:92 | myConstKey |
5353
| rncryptor.swift:60:24:60:24 | abcdef123456 | rncryptor.swift:60:19:60:38 | call to Data.init(_:) |
5454
nodes
55+
| SQLite.swift:43:13:43:13 | hardcoded_key | semmle.label | hardcoded_key |
56+
| SQLite.swift:45:23:45:23 | hardcoded_key | semmle.label | hardcoded_key |
57+
| SQLite.swift:47:15:47:15 | hardcoded_key | semmle.label | hardcoded_key |
58+
| SQLite.swift:49:79:49:79 | hardcoded_key | semmle.label | hardcoded_key |
5559
| cryptoswift.swift:76:3:76:3 | this string is constant | semmle.label | this string is constant |
5660
| cryptoswift.swift:90:26:90:121 | [...] | semmle.label | [...] |
5761
| cryptoswift.swift:92:18:92:36 | call to getConstantString() | semmle.label | call to getConstantString() |
@@ -111,6 +115,10 @@ subpaths
111115
| 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 |
112116
| 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] |
113117
#select
118+
| SQLite.swift:43:13:43:13 | hardcoded_key | SQLite.swift:43:13:43:13 | hardcoded_key | SQLite.swift:43:13:43:13 | hardcoded_key | The key 'hardcoded_key' has been initialized with hard-coded values from $@. | SQLite.swift:43:13:43:13 | hardcoded_key | hardcoded_key |
119+
| SQLite.swift:45:23:45:23 | hardcoded_key | SQLite.swift:45:23:45:23 | hardcoded_key | SQLite.swift:45:23:45:23 | hardcoded_key | The key 'hardcoded_key' has been initialized with hard-coded values from $@. | SQLite.swift:45:23:45:23 | hardcoded_key | hardcoded_key |
120+
| SQLite.swift:47:15:47:15 | hardcoded_key | SQLite.swift:47:15:47:15 | hardcoded_key | SQLite.swift:47:15:47:15 | hardcoded_key | The key 'hardcoded_key' has been initialized with hard-coded values from $@. | SQLite.swift:47:15:47:15 | hardcoded_key | hardcoded_key |
121+
| SQLite.swift:49:79:49:79 | hardcoded_key | SQLite.swift:49:79:49:79 | hardcoded_key | SQLite.swift:49:79:49:79 | hardcoded_key | The key 'hardcoded_key' has been initialized with hard-coded values from $@. | SQLite.swift:49:79:49:79 | hardcoded_key | hardcoded_key |
114122
| 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 |
115123
| cryptoswift.swift:109:21:109:21 | keyString | cryptoswift.swift:76:3:76:3 | this string is constant | cryptoswift.swift:109:21:109: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 |
116124
| cryptoswift.swift:117:22:117:22 | key | cryptoswift.swift:90:26:90:121 | [...] | cryptoswift.swift:117:22:117:22 | key | The key 'key' has been initialized with hard-coded values from $@. | cryptoswift.swift:90:26:90:121 | [...] | [...] |

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ func test_sqlite_swift_api(dbPath: String, goodKey: String, goodArray: [UInt8])
4040
// methods taking a string key
4141

4242
try db.key(goodKey)
43-
try db.key("hardcoded_key") // BAD [NOT DETECTED]
43+
try db.key("hardcoded_key") // BAD
4444
try db.keyAndMigrate(goodKey)
45-
try db.keyAndMigrate("hardcoded_key") // BAD [NOT DETECTED]
45+
try db.keyAndMigrate("hardcoded_key") // BAD
4646
try db.rekey(goodKey)
47-
try db.rekey("hardcoded_key") // BAD [NOT DETECTED]
47+
try db.rekey("hardcoded_key") // BAD
4848
try db.sqlcipher_export(Connection.Location.uri("encryptedDb.sqlite3"), key: goodKey)
49-
try db.sqlcipher_export(Connection.Location.uri("encryptedDb.sqlite3"), key: "hardcoded_key") // BAD [NOT DETECTED]
49+
try db.sqlcipher_export(Connection.Location.uri("encryptedDb.sqlite3"), key: "hardcoded_key") // BAD
5050

5151
// Blob variant
5252

0 commit comments

Comments
 (0)