Repository navigation
Description
Target Language
swift
Query Name (Optional)
MemorySafety
Query Type
Security
Query Description
AI Scan reported 1 high-severity CWE-125 (memory safety) finding(s) in Swift public synthetic repositories that the baseline CodeQL default-setup scan did not report. Gap categories: missing-query. Existing queries considered: none.
Why CodeQL appears to have missed these (unverified until reproduced with a test database):
- No installed Swift query covers unsafe pointer arithmetic with attacker-controlled offsets; a rule needs precise Data/UnsafePointer bounds modeling.
Linked findings (gap-key: swift/query-create/memory-safety)
| Repo | CWE | Severity | AI scan alert | Summary |
|---|---|---|---|---|
| OversecuredVulnerableiOSApp | CWE-125 | high | https://github.com/codeql-forks-felickz/OversecuredVulnerableiOSApp/security/code-scanning/6 | The public deep-link save route accepts an unrestricted signed integer offset and uses it in unsafe pointer arithmetic while computing a copy length. Negative offsets access memory before the decoded data; offsets larger than the data length produce an invalid negative count. An attacker can trigger out-of-bounds reads or a process crash through a crafted ovia URL. |
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.
Expected Severity
High
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.
CWE/CVE Reference (Optional)
CWE-125
References (Optional)
https://cwe.mitre.org/data/definitions/125.html
Code of Conduct
- I agree to follow this project's Code of Conduct
Activity
felickz commentedon Oct 31, 2026
Update: additional medium and low severity findings fit this gap (gap-key
swift/query-create/memory-safety). They are listed with full context so the Copilot agent can re-validate each one against the proposed change and extend it where it does not cover them.Linked findings
Data.aes()always passeskeyLength = size_t(kCCKeySizeAES128)(16) toCCCrypt()while the key pointer comes from the caller-supplied `String.aesEncrypt(key:iv:options:)/String.aesDecrypt(key:iv:options:)hard-codekeyLength = size_t(kCCKeySizeAES128)(16 bytes) whilHandling
Create a new CodeQL query. No existing query covers these patterns (most findings are gap type
query-absentormissing-query). Because coverage of lower-severity patterns can be heuristic, target Community Packs unless precision is shown to be high enough for github/codeql.Patterns
query-absent(2 findings), for example iGoat-Swift iGoat-Swift/iGoat-Swift/Source/Extensions/Data+Extension.swiftFinding details
1. iGoat-Swift iGoat-Swift/iGoat-Swift/Source/Extensions/Data+Extension.swift:11 (CWE-125, medium)
Data.aes()always passeskeyLength = size_t(kCCKeySizeAES128)(16) toCCCrypt()while the key pointer comes from the caller-supplied `2. iGoat-Swift iGoat-Swift/iGoat-Swift/Source/Extensions/NSString+Extension.swift:10 (CWE-125, medium)
String.aesEncrypt(key:iv:options:)/String.aesDecrypt(key:iv:options:)hard-codekeyLength = size_t(kCCKeySizeAES128)(16 bytes) whilfelickz commentedon Nov 3, 2026
Upstream triage
precision:lowAudit-grade or weak signal. 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.Linked pull request: #103
Why. New query, so github/codeql would need very-high precision. The pointer-offset query is a sound taint design over public Swift APIs, but its barrier only sees if/guard comparisons (precondition, assert and helpers are missed) and it matches stdlib names by string. The bundled key-length query is a syntactic audit check without taint. No stock Swift query covers this, so experimental Community Packs fits once a real-project true positive exists.
mediumin the pull request). Pointer query is taint based but its barrier only sees if/guard comparisons and range checks; the bundled key-length query is a syntactic audit check (any Data key parameter plus kCCKeySizeAES128, no local count check), no taint.Concerns, overlap and next steps
False-positive concerns
Performance concerns
Heuristics used
What an upstream change would look like. Community Packs swift/src/<category>/ (the Swift pack has no queries yet) with swift/test inline-expectation tests; URLComponents summaries stay QL SummaryModelCsv since Swift has no MaD YAML.
Before opening an upstream pull request
Split note. Two unrelated queries are bundled: swift/untrusted-pointer-offset (medium, taint based, the real subject of the issue) and swift/untrusted-crypto-key-length (low, audit grade, no taint). Overall precision is the lower one.
This is a recommendation only. A human reviews it before any pull request is opened against
github/codeqlor the Community Packs repository.