Repository navigation
Description
Query File Path
swift/static-initialization-vector
Update Type
Enhanced detection coverage
Issue Description
AI Scan reported 2 medium-severity CWE-329 (weak crypto randomness) finding(s) in Swift public synthetic repositories that the baseline CodeQL default-setup scan did not report. Gap categories: missing-sink, missing-source. Existing queries considered: swift/static-initialization-vector.
Why CodeQL appears to have missed these (unverified until reproduced with a test database):
- Passing nil as the IV to CCCrypt means a zero IV; the static IV query does not treat a nil literal as constant.
- A hard-coded IV supplied as a default parameter value likely escapes swift/static-initialization-vector.
Linked findings (gap-key: swift/query-update/weak-crypto-randomness)
| Repo | CWE | Severity | AI scan alert | Summary |
|---|---|---|---|---|
| iGoat-Swift | CWE-329 | medium | https://github.com/codeql-forks-felickz/iGoat-Swift/security/code-scanning/35 | WebkitCacheExerciseVC.aesCBCDecrypt(data:keyData:) passes nil as the IV argument to CCCrypt(), which CommonCrypto interprets as an all |
| iGoat-Swift | CWE-329 | medium | https://github.com/codeql-forks-felickz/iGoat-Swift/security/code-scanning/20 | The shared AES helper defaults every encryption to the same hard-coded IV and uses CBC with padding but no authentication tag. Reusing an IV |
Findings come from AI Scan on public synthetic apps. Hypotheses above are unverified until reproduced with a test database. Verify first whether CodeQL already covers a case (for example via a different query or threat model) before adding code.
Handling decision
- Type: Query Update
- Decision: Update existing CodeQL queries. The queries named above already target this weakness class; the findings show missing flow steps, sinks, sources, barriers or scope handling. Extend the smallest existing query or model instead of adding a new query.
- Recommended actions across the findings: extend-existing-query (2)
Patterns in this gap
static-iv-nil(1 finding), for example iGoat-Swift iGoat-Swift/iGoat-Swift/Source/Exercises/InsecureLocalDataStorage/WebKit Cache/WebkitCacheExerciseVC.swiftstatic-iv-default-parameter(1 finding), for example iGoat-Swift iGoat-Swift/iGoat-Swift/Source/Extensions/Data+Extension.swift
Finding details
Each finding below has its own context so the agent can work from this issue alone.
1. iGoat-Swift iGoat-Swift/iGoat-Swift/Source/Exercises/InsecureLocalDataStorage/WebKit Cache/WebkitCacheExerciseVC.swift:141 (CWE-329, medium)
- AI Scan alert: https://github.com/codeql-forks-felickz/iGoat-Swift/security/code-scanning/35
- AI Scan message:
WebkitCacheExerciseVC.aesCBCDecrypt(data:keyData:)passesnilas the IV argument toCCCrypt(), which CommonCrypto interprets as an all - Context for the agent: A Swift decrypt helper calls CCCrypt with a nil IV argument. CodeQL would need nil literals at the IV parameter to count as a static IV.
- Why CodeQL appears to miss it: missing-sink: Passing nil as the IV to CCCrypt means a zero IV; the static IV query does not treat a nil literal as constant.
- Existing CodeQL queries considered: swift/static-initialization-vector
- Recommended action from the comparison: extend-existing-query (classification confidence: medium)
2. iGoat-Swift iGoat-Swift/iGoat-Swift/Source/Extensions/Data+Extension.swift:5 (CWE-329, medium)
- AI Scan alert: https://github.com/codeql-forks-felickz/iGoat-Swift/security/code-scanning/20
- AI Scan message: The shared AES helper defaults every encryption to the same hard-coded IV and uses CBC with padding but no authentication tag. Reusing an IV
- Context for the agent: Data+Extension.swift:5 defines an AES helper whose IV parameter defaults to a constant literal used with CBC. CodeQL would need to treat default argument literals as constant sources reaching the IV sink.
- Why CodeQL appears to miss it: missing-source: A hard-coded IV supplied as a default parameter value likely escapes swift/static-initialization-vector.
- Existing CodeQL queries considered: swift/static-initialization-vector
- Recommended action from the comparison: extend-existing-query (classification confidence: medium)
Proposed Solution
- Reproduce each linked finding with a minimal synthetic test case and confirm the baseline result.
- Identify the missing source, sink, summary or scope condition and extend the smallest model or query that fixes it.
- Add positive and negative tests and a change note.
- Check the false-positive rate on the other linked findings before widening.
Code Examples
See the linked alerts above for the vulnerable pattern; reduce each to a minimal test case with a safe counterpart that should not alert.
Breaking Change?
No - backward compatible
References (Optional)
https://cwe.mitre.org/data/definitions/329.html
Code of Conduct
- I agree to follow this project's Code of Conduct
Activity
felickz commentedon Nov 3, 2026
Upstream triage
precision:mediumRelies on heuristics or accepted over-approximation. Community Packs, always tags:experimental.
tags:experimental
Goes to Community Packs: performance, false-positive or synthetic-only concerns.
Community Packs, experimental. Recommended for the Community Packs repository, not
github/codeql. The issue is labeledtags:experimentalfor this.Separable piece. CommonCrypto key and IV sink rows and nil IV. This part could be proposed to
github/codeqlon its own, see the split note below.Linked pull request: #351
Possible overlap with #102 (the same CommonCrypto key and IV sink rows), so one upstream pull request may cover several issues.
Why. Stock static-initialization-vector has no CommonCrypto sinks, so constant or nil IVs passed to CCCrypt and CCCryptorCreate* are missed, a real gap for a widely used iOS API. The sink positions, nil semantics and ECB/RC4 exclusion are sound. The default-argument source is unconstrained, so default nil or random IVs can alert. Keep experimental for now; a trimmed sink-and-nil patch could be proposed to github/codeql separately.
mediumin the pull request). CommonCrypto sinks are exact by API position, nil is a documented all-zero IV, ECB and RC4 are excluded and flow reuses stock sources (very-high to high). The default-argument source accepts any non-caller-side default without a constant check, which lowers the PR to medium.Concerns, overlap and next steps
False-positive concerns
Performance concerns
Heuristics used
What an upstream change would look like. Community Packs swift/src/<category>/ query with tests in swift/test/. Separately, a github/codeql patch to StaticInitializationVectorExtensions.qll (CommonCrypto IV sinks, nil IV limited to them), tests under swift/ql/test/query-tests/Security/CWE-1204, library change note.
Before opening an upstream pull request
Split note. The CommonCrypto sinks plus nil IV (with the ECB/RC4 exclusion) are a strong github/codeql patch candidate. The default-argument source is the over-approximate part; split it out or add a constant-default check before proposing upstream.
Change from the initial guess. When this issue was opened the coarse destination guess was
github/codeql. Reading the actual pull request changed it to Community Packs.This is a recommendation only. A human reviews it before any pull request is opened against
github/codeqlor the Community Packs repository.