Repository navigation
Description
Target Language
swift
Query Name (Optional)
Cwe20
Query Type
Security
Query Description
AI Scan reported 2 medium-severity CWE-20 (cwe 20) finding(s) in Swift public synthetic repositories that the baseline CodeQL default-setup scan did not report. Gap categories: missing-source, query-absent. Existing queries considered: none.
Why CodeQL appears to have missed these (unverified until reproduced with a test database):
- Custom URL scheme query parameters in application(_:open:options:) are unvalidated input but no matching query or source for this use exists.
- Unchecked substring ranges from a response can crash or misparse; no Swift query covers unvalidated delimiter lookups.
Linked findings (gap-key: swift/query-create/cwe-20)
| Repo | CWE | Severity | AI scan alert | Summary |
|---|---|---|---|---|
| iGoat-Swift | CWE-20 | medium | https://github.com/codeql-forks-felickz/iGoat-Swift/security/code-scanning/40 | AppDelegate.application(_:open:options:) handles the iGoat:// custom URL scheme and takes the contactNumber and message query parame |
| iGoat-Swift | CWE-20 | medium | https://github.com/codeql-forks-felickz/iGoat-Swift/security/code-scanning/58 | The parser performs substring operations using ranges from an untrusted HTTP response without checking whether either delimiter was found. A |
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 Create
- Decision: 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. - Recommended actions across the findings: write-new-query (2)
Patterns in this gap
url-scheme-input-validation(1 finding), for example iGoat-Swift iGoat-Swift/iGoat-Swift/AppDelegate.swiftunchecked-substring-range(1 finding), for example iGoat-Swift iGoat-Swift/iGoat-Swift/Source/Exercises/Key Management/Key Storage Server Side/KeyStorageServerSideVC.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/AppDelegate.swift:16 (CWE-20, medium)
- AI Scan alert: https://github.com/codeql-forks-felickz/iGoat-Swift/security/code-scanning/40
- AI Scan message:
AppDelegate.application(_:open:options:)handles theiGoat://custom URL scheme and takes thecontactNumberandmessagequery parame - Context for the agent: A Swift app delegate reads query parameters from a custom URL scheme and uses them without validation. CodeQL would need the open-URL handler as a remote source and a sensitive action sink.
- Why CodeQL appears to miss it: missing-source: Custom URL scheme query parameters in application(_:open:options:) are unvalidated input but no matching query or source for this use exists.
- Recommended action from the comparison: write-new-query (classification confidence: low)
2. iGoat-Swift iGoat-Swift/iGoat-Swift/Source/Exercises/Key Management/Key Storage Server Side/KeyStorageServerSideVC.swift:70 (CWE-20, medium)
- AI Scan alert: https://github.com/codeql-forks-felickz/iGoat-Swift/security/code-scanning/58
- AI Scan message: The parser performs substring operations using ranges from an untrusted HTTP response without checking whether either delimiter was found. A
- Context for the agent: A Swift parser takes ranges from range(of:) on an HTTP response and slices without checking for nil. CodeQL would need a query for unchecked optional ranges used in substring operations.
- Why CodeQL appears to miss it: query-absent: Unchecked substring ranges from a response can crash or misparse; no Swift query covers unvalidated delimiter lookups.
- Recommended action from the comparison: write-new-query (classification confidence: low)
Expected Severity
Medium
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-20
References (Optional)
https://cwe.mitre.org/data/definitions/20.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.Linked pull request: #350
Why. Two unrelated new queries. The unchecked range(of:) query has no untrusted source and misses common guards such as length > 0, so safe code alerts. The URL scheme query re-declares sources that the stock library already models as remote and adds low-impact sinks (alert text, message and mail composers, open) behind a loose any-Bool-call-validates barrier. Better as experimental Community Packs queries than github/codeql.
mediumin the pull request). Unchecked range(of:) has no untrusted source and only accepts NSNotFound or zero-length checks. The URL scheme query is flow based with narrow sinks and a broad barrier (any Bool call or comparison on the value). Both rely on mitigation-absent logic.Concerns, overlap and next steps
False-positive concerns
Performance concerns
Heuristics used
What an upstream change would look like. Two separate Community Packs queries under swift/src/<category>/ with tests in swift/test/. If kept, the deep link query should use the stock RemoteFlowSource instead of its own CustomUrlSchemeSource copy.
Before opening an upstream pull request
Split note. Two independent queries. The URL scheme query is closer to upstream quality (flow based, public sources already modeled) but its sinks are low impact; neither meets the github/codeql bar. Keep both experimental.
This is a recommendation only. A human reviews it before any pull request is opened against
github/codeqlor the Community Packs repository.