Repository navigation
Conversation
Establish a byte-for-byte baseline from original Swift for the unified Swift port, including query help and its sample. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 907904bb-29a3-48f9-8afe-9ee16e84f617
Copy the original Swift data flow configuration and query-specific models into the query source without adapting their declarations. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 907904bb-29a3-48f9-8afe-9ee16e84f617
Use unified integer literals and models-as-data PBKDF iteration sinks. Update the query ID and test reference and regenerate the baseline, retaining all four original alerts and the interprocedural source expectation. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 907904bb-29a3-48f9-8afe-9ee16e84f617
This should be fixed once we have a better way of getting the actual semantic value out of a literal (requires extractor changes). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 907904bb-29a3-48f9-8afe-9ee16e84f617
|
QHelp previews: unified/ql/src/queries/security/CWE-916/InsufficientHashIterations.qhelpInsufficient hash iterationsStoring cryptographic hashes of passwords is standard security practice, but it is equally important to select the right hashing scheme. If an attacker obtains the hashed passwords of an application, the password hashing scheme should still prevent the attacker from easily obtaining the original cleartext passwords. A good password hashing scheme requires a computation that cannot be done efficiently. Hashing schemes with low number of iterations are efficiently computable, and are therefore not suitable for password hashing. RecommendationUse the OWASP recommendation for sufficient number of iterations (currently, that is greater than or equal to 120,000) for password hashing schemes. ExampleThe following example shows a few cases where a password hashing scheme is instantiated. In the 'BAD' cases, the scheme is initialized with insufficient iterations, making it susceptible to password cracking attacks. In the 'GOOD' cases, the scheme is initialized with at least 120,000 iterations, which protects the hashed data against recovery. func hash() {
// ...
// BAD: Using insufficient (that is, < 120,000) iterations for password hashing
_ = try PKCS5.PBKDF1(password: getRandomArray(), salt: getRandomArray(), iterations: 90000, keyLength: 0)
_ = try PKCS5.PBKDF2(password: getRandomArray(), salt: getRandomArray(), iterations: 90000, keyLength: 0)
// GOOD: Using sufficient (that is, >= 120,000) iterations for password hashing
_ = try PKCS5.PBKDF1(password: getRandomArray(), salt: getRandomArray(), iterations: 120120, keyLength: 0)
_ = try PKCS5.PBKDF2(password: getRandomArray(), salt: getRandomArray(), iterations: 310000, keyLength: 0)
// ...
}References
|
cc15577 to
7f427d1
Compare
7f427d1 to
ee101fb
Compare
There was a problem hiding this comment.
🟡 Changes recommended
DCA comparison data is missing to assess acceptance-relevant changes in findings and performance from the new production flow analysis; focused regression tests do not provide this comparison.
1 open issue
What changed in this PR
Ports the insufficient hash iterations query to Unified for Swift, preserving the four original test alerts.
Changes:
- Adds the query, help text, and Swift examples.
- Models CryptoSwift PBKDF1/PBKDF2 iteration arguments as sinks.
- Adds regression tests, including a documented missing alert for underscore-separated literals.
| File | Description |
|---|---|
unified/ql/test/query-tests/security/CWE-916/InsufficientHashIterations/test.swift |
Adds positive, negative, and numeric-separator cases. |
unified/ql/test/query-tests/security/CWE-916/InsufficientHashIterations/InsufficientHashIterations.qlref |
Connects the query to inline expectation checks. |
unified/ql/test/query-tests/security/CWE-916/InsufficientHashIterations/InsufficientHashIterations.expected |
Records four alerts and their flow paths. |
unified/ql/src/queries/security/CWE-916/InsufficientHashIterations.swift |
Illustrates insufficient and sufficient iteration counts. |
unified/ql/src/queries/security/CWE-916/InsufficientHashIterations.ql |
Detects low iteration counts flowing into hashing calls. |
unified/ql/src/queries/security/CWE-916/InsufficientHashIterations.qhelp |
Documents the query and recommendations. |
unified/ql/lib/ext/crypto.model.json |
Adds iteration-count sinks for PBKDF constructors. |
Review effort: Balanced (adaptive)

This ports
swift/insufficient-hash-iterationsto Unified+Swift using the skill we have for doing so. The port retains the four original alerts in tests.My manual changes where: Removing some changes Copilot made that didn't make much sense, for instance odd edits to the qhelp and handling
_in literals specifically in the query, which is not the right place to do it. I also added a test with_in literals and formatted the tests withswift format.The qhelp is unchanged from the legacy Swift one. Does that mean we don't need a docs re-review?