Skip to content

Unified: Port insufficient hash iterations query to Swift - #23358

Open
paldepind wants to merge 5 commits into
mainfrom
unified/swift/insufficient-hash-iterations
Open

paldepind wants to merge 5 commits into
mainfrom
unified/swift/insufficient-hash-iterations

Conversation

@paldepind

@paldepind paldepind commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

This ports swift/insufficient-hash-iterations to 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 with swift format.

The qhelp is unchanged from the legacy Swift one. Does that mean we don't need a docs re-review?

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
@github-actions

github-actions Bot commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

QHelp previews:

unified/ql/src/queries/security/CWE-916/InsufficientHashIterations.qhelp

Insufficient hash iterations

Storing 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.

Recommendation

Use the OWASP recommendation for sufficient number of iterations (currently, that is greater than or equal to 120,000) for password hashing schemes.

Example

The 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

@paldepind
paldepind force-pushed the unified/swift/insufficient-hash-iterations branch from cc15577 to 7f427d1 Compare December 4, 2026 09:23
@paldepind
paldepind force-pushed the unified/swift/insufficient-hash-iterations branch from 7f427d1 to ee101fb Compare December 4, 2026 09:33
@paldepind
paldepind requested an adaptive review from Copilot December 4, 2026 09:43

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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)

@paldepind
paldepind marked this pull request as ready for review December 4, 2026 10:03
@paldepind
paldepind requested a review from a team as a code owner December 4, 2026 10:03
@paldepind paldepind added the no-change-note-required This PR does not need a change note label Dec 4, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation no-change-note-required This PR does not need a change note Unified

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants