Repository navigation
Conversation
1 task done
…to, nil and default-parameter IVs Co-authored-by: felickz <1760475+felickz@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Update query for enhanced detection of weak cryptography
[UPDATE QUERY] Swift: report nil, CommonCrypto and default-parameter IVs that Oct 31, 2026
swift/static-initialization-vector misses
There was a problem hiding this comment.
🟡 Changes recommended
The newly discovered Swift suite cannot run in the Linux-only workflow, and overly broad ECB/RC4 matching can suppress genuine static- or nil-IV findings.
2 open issues
What changed in this PR
Adds a custom Swift query to complement upstream static-IV detection, covering the CommonCrypto and default-parameter cases described in #301 without modifying the upstream query.
Changes:
- Models CommonCrypto IV arguments, nil/default sources, and flow through nested closures.
- Adds ECB/RC4 exclusions and filtering to avoid repeating upstream results.
- Introduces Swift query/test packs, regression fixtures, query help, and a change note.
| File | Description |
|---|---|
languages/swift/custom/test/StaticInitializationVectorExtended/test.swift |
Adds positive and negative Swift fixtures. |
languages/swift/custom/test/StaticInitializationVectorExtended/StaticInitializationVectorExtended.qlref |
Connects the query to inline-expectation processing. |
languages/swift/custom/test/StaticInitializationVectorExtended/StaticInitializationVectorExtended.expected |
Records expected alerts and flow paths. |
languages/swift/custom/test/qlpack.yml |
Defines the Swift test pack. |
languages/swift/custom/src/StaticInitializationVectorExtended/StaticInitializationVectorExtended.qll |
Implements extended detection and result filtering. |
languages/swift/custom/src/StaticInitializationVectorExtended/StaticInitializationVectorExtended.ql |
Defines query metadata and path-result selection. |
languages/swift/custom/src/StaticInitializationVectorExtended/StaticInitializationVectorExtended.md |
Documents coverage, remediation, and limitations. |
languages/swift/custom/src/qlpack.yml |
Defines the Swift query pack. |
languages/swift/custom/src/change-notes/2026-10-31-static-initialization-vector-extended.md |
Announces the new query and its coverage. |
Review effort: Balanced
Co-authored-by: felickz <1760475+felickz@users.noreply.github.com>
Co-authored-by: felickz <1760475+felickz@users.noreply.github.com>
Co-authored-by: felickz <1760475+felickz@users.noreply.github.com>
1 task done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


📝 Query Update
languages/swift/custom/src/StaticInitializationVectorExtended/StaticInitializationVectorExtended.ql. It complements upstreamswift/static-initialization-vector, which is reused unchanged.🎯 Changes
What Changed
swift/custom/static-initialization-vector-extended. It reuses upstream's sources, sinks, barriers and extension points, and adds the following:CCCryptandCCCryptorCreate(argument 5),CCCryptorCreateWithMode(argument 4) andCCCryptorReset(argument 1).nilliterals. These are reported only at CommonCrypto sinks, because RNCryptor generates a random IV when givennil.DefaultArgumentExpr(a call that omits an argument with a default value). Defaults that Swift fills in at the call site are excluded.withUnsafeBytes/withUnsafeMutableBytesto the closure's pointer parameter. This covers the deprecated genericDataoverload.kCCOptionECBMode,kCCModeECB) or RC4 (kCCAlgorithmRC4,kCCModeRC4), since these ignore the IV.languages-swift-custom-srcandlanguages-swift-custom-test. The repo had no Swift directory before..md) and anewQuerychange note.Why This Change
Both iGoat-Swift CWE-329 findings reproduce. Upstream reports neither:
nilIV: upstream has no CommonCrypto sinks, andnilis not one of its sources. CommonCrypto replaces anilIV with all zero bytes.ParamDecl. The only thing that can be modelled is the call that omits the argument. In iGoat the IV then passes through nestedwithUnsafeBytesclosures before it reachesCCCrypt.The query is a custom one rather than an edit to upstream because upstream lives in
codeql/swift-all.Impact
New alerts where a constant,
nilor default-parameter IV reaches a CommonCrypto call, or where a default-parameter IV reaches an upstream sink. Upstream results do not change, and this query does not repeat them.🔍 Before vs. After
Previous Behavior
No alerts.
New Behavior
CCCrypt(..., nil, ...)is reported as "A nil initialization vector (all zero bytes) is used for encryption."CCCrypt(..., ivBytes, ...)is reported with a path back toplain.aes(keyData: key), as "The default value of parameter 'ivData' is used as an initialization vector for encryption."🧪 Testing
codeql test run -- StaticInitializationVectorExtended/is still needed.swift/static-initialization-vectoron the same database reports only the CryptoSwiftCBC(iv:)case.test/StaticInitializationVectorExtended/test.swiftis an inline-expectations test ($ Alert/$ Source):CCCrypt/CCCryptorCreatenilpassed toCCCryptorCreate,CCCryptorCreateWithMode(CBC) andCCCryptorResetCCCryptorCreateWithModeECB modenilpassed to RNCryptorCBC(iv:), which upstream already reportsThe
withUnsafeBytesstubs deliberately never callbody, to match Foundation, so the test depends on the custom flow steps.Notes on the Linux run:
codeql database upgrade, then rancodeql test run --reuse-dataset.-disable-stack-protector. That option is set only in a temporary copy of the test file, not in the committed one.📊 Impact Analysis
withUnsafe*Bytescalls.medium. Known false-positive risks:iv: Data = randomIV()) is still reported, because the default value is not in the database. This is documented in the query help.nilIV is reported on purpose: it means the data was encrypted with an all-zero IV.📋 Checklist
--warnings=error)@id swift/custom/static-initialization-vector-extended, CWE-329/1204)🔗 References
qlpack.ymlfiles (expect an identical add/add): [UPDATE QUERY] Swift: report local user input reachingswift/unsafe-webview-fetchsinks #333