Repository navigation
Conversation
Copy the original Swift WeakPasswordHashing query, query help, examples, and query tests byte-for-byte into unified/ to establish an unchanged baseline for the unified Swift port. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…nd models Inline the data flow configuration and query-specific models unchanged from WeakPasswordHashingQuery.qll, WeakPasswordHashingExtensions.qll, and WeakSensitiveDataHashingExtensions.qll, marking their provenance before adapting to unified Swift APIs. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Adapt WeakPasswordHashing.ql to unified Swift using SensitiveData password sources, existing models-as-data sinks from legacy-swift.model.json, and an implementation barrier covering HMAC/PBKDF1/PBKDF2 declarations and extensions. Update the query ID, .qlref, and inline test expectations. All 48 original positive cases are detected with 0 testFailures. Because LegacyMaD currently ignores receiver types for method calls, overloaded sink names (hash, update, calculate) match multiple algorithm models per call site (152 #select rows total). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Correct the four CryptoSwift SHA3 sink models in legacy-swift.model.json that mistakenly used weak-password-hash-input-SHA2 instead of weak-password-hash-input-SHA3, and update WeakPasswordHashing.expected. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add test cases covering the HMAC/PBKDF1/PBKDF2 implementation barrier (both struct and extension declarations, plus a control helper) in testCryptoSwift.swift, and a SHA256.self metatype password-hashing case in testCryptoKit.swift. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Update the libsodium bindings anchor from #bindings-programming-languages to #bindings-for-programming-languages in WeakPasswordHashing.qhelp. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
…ne unchanged Copy the original Swift WeakSensitiveDataHashing query, query help, examples, .qlref, and .expected byte-for-byte into unified/ to establish an unchanged baseline for the unified Swift port (reusing the shared CWE-328 .swift test files). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…tion and models Inline the data flow configuration and query-specific models unchanged from WeakSensitiveDataHashingQuery.qll and WeakSensitiveDataHashingExtensions.qll, marking their provenance before adapting to unified Swift APIs. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…aseline Adapt WeakSensitiveDataHashing.ql to unified Swift using SensitiveData sources (excluding passwords, which are handled by unified/swift/weak-password-hashing) and existing weak-hash-input-* models from legacy-swift.model.json. Update the query ID, .qlref, and inline expectations in the shared CWE-328 tests. All 37 expected positive cases (including all 6 metatype/flow cases in testWithFlowAndMetatypes, even the previously missed generic testReceiver3) are detected with 0 testFailures (172 #select rows total). Because LegacyMaD currently ignores receiver types for method calls, SHA256/SHA384/SHA512 hash/update and SHA2/SHA3 calculate calls currently produce SPURIOUS alerts documented via inline expectations. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…g.qhelp Update the renamed OWASP Transport Layer Protection Cheat Sheet URL and label to Transport Layer Security Cheat Sheet in WeakSensitiveDataHashing.qhelp, and remove the stray executable bit inherited from the original Swift files. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…ce the test is shared.
|
QHelp previews: unified/ql/src/queries/security/CWE-328/WeakPasswordHashing.qhelpUse of an inappropriate cryptographic hashing algorithm on passwordsHash functions that are not sufficiently computationally hard can leave data vulnerable. You should not use such functions for password hashing. A strong cryptographic hash function should be resistant to:
Password hashing algorithms should be slow and/or memory intensive to compute, to make brute force attacks more difficult. RecommendationFor password storage, you should use a sufficiently computationally hard cryptographic hash function, such as one of the following:
ExampleThe following examples show two versions of the same function. In both cases, a password is hashed using a cryptographic hashing algorithm. In the first case, the SHA-512 hashing algorithm is used. It is vulnerable to offline brute force attacks: let passwordData = Data(passwordString.utf8)
let passwordHash = Crypto.SHA512.hash(data: passwordData) // BAD: SHA-512 is not suitable for password hashing.
// ...
if Crypto.SHA512.hash(data: Data(passwordString.utf8)) == passwordHash {
// ...
}Here is the same function using Argon2, which is suitable for password hashing: import Argon2Swift
let salt = Salt.newSalt()
let result = try! Argon2Swift.hashPasswordString(password: passwordString, salt: salt) // GOOD: Argon2 is suitable for password hashing.
let passwordHash = result.encodedString()
// ...
if try! Argon2Swift.verifyHashString(password: passwordString, hash: passwordHash) {
// ...
}References
unified/ql/src/queries/security/CWE-328/WeakSensitiveDataHashing.qhelpUse of a broken or weak cryptographic hashing algorithm on sensitive dataUsing a broken or weak cryptographic hash function can leave data vulnerable, and should not be used in security related code. A strong cryptographic hash function should be resistant to:
Since it's OK to use a weak cryptographic hash function in a non-security context, this query only alerts when these are used to hash sensitive data (such as usernames, identifying information and private data). RecommendationEnsure that you use a strong, modern cryptographic hash function, such as:
ExampleThe following examples show a function for fetching data from a URL and computing a hash of the data, perhaps to check the data has not been tampered with. In the first case the MD5 hashing algorithm is used that is known to be vulnerable to collision attacks. func getContentsAndHash(url: URL) -> (Data, String)? {
guard let data = try? Data(contentsOf: url) else {
return nil
}
let digest = Insecure.MD5.hash(data: data) // BAD: MD5 is not suitable for hashing sensitive data.
let hash = digest.map { String(format: "%02hhx", $0) }.joined()
return (data, hash)
}Here is the same function using SHA-512, which is a strong cryptographic hashing function. func getContentsAndHash(url: URL) -> (Data, String)? {
guard let data = try? Data(contentsOf: url) else {
return nil
}
let digest = SHA512.hash(data: data) // GOOD: SHA-512 is suitable for hashing sensitive data.
let hash = digest.map { String(format: "%02hhx", $0) }.joined()
return (data, hash)
}References
|
Ports the
swift/weak-sensitive-data-hashingquery to unified Swift asunified/swift/weak-sensitive-data-hashing. Most of the implementation work was done by Copilot (Gemini 4 Neon High Effort), in the same context asunified/swift/weak-password-hashingwas ported - it seemed to know exactly what needed to happen for this closely related query.There are some spurious test results, I believe all of these are due to the current limitation with models-as-data method qualifier matching. No missing results.
TODO: