Skip to content

[Data Extension Create]: CWE-22 HIGH - Swift: data extension models for path traversal #104

Open

Description

@felickz

Target Language

swift

Library Repository / Documentation URL

To be determined from the linked findings

Data Extension Name (Optional)

cwe-22.model.yml

Library Modules / Components

See linked findings for the frameworks involved.

Data Extension Description

AI Scan reported 1 high-severity CWE-22 (path traversal) finding(s) in Swift public synthetic repositories that the baseline CodeQL default-setup scan did not report. Gap categories: missing-summary. Existing queries considered: swift/path-injection.

Why CodeQL appears to have missed these (unverified until reproduced with a test database):

  • Custom URL schemes are modeled as remote sources and Data.write(to:) as a sink; the likely missing link is the helper that builds the Documents URL.

Linked findings (gap-key: swift/data-extension-create/path-traversal)

Repo CWE Severity AI scan alert Summary
OversecuredVulnerableiOSApp CWE-22 high https://github.com/codeql-forks-felickz/OversecuredVulnerableiOSApp/security/code-scanning/3 The public deep-link save route uses the attacker-controlled name directly as a path component under Documents. Values containing traversal components can escape Documents within the app sandbox; decoded attacker data is then written there without any path containment check or user confirmation.

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.

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.

Additional References (Optional)

https://cwe.mitre.org/data/definitions/22.html

Code of Conduct

  • I agree to follow this project's Code of Conduct

Activity

  1. added
    enhancement
    CWE-22
    severity:high
    on Oct 16, 2026
  2. added
    precision:medium
    tags:experimental
    on Nov 3, 2026
  3. felickz commented on Nov 3, 2026

    @felickz
    Author

    Upstream triage

    precision:medium Relies 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 labeled tags:experimental for this.

    Separable piece. URLComponents, NSURLComponents and URLQueryItem models. This part could be proposed to github/codeql on its own, see the split note below.

    Linked pull request: #107

    Why. The URLComponents, NSURLComponents and URLQueryItem models (init summaries, field taint) are exact Foundation additions that github/codeql does not appear to contain, and URLComponents is common in iOS deep link parsing. The PR also adds a receiver-insensitive, field-based UIViewController property step, and the query copies swift/path-injection. Recommend Community Packs for the whole PR, and propose the models upstream separately.

    Change Data extension (model) addition
    Target swift/path-injection: URLComponents/NSURLComponents/URLQueryItem taint models and a UIViewController property step
    Precision assessed medium (declared high in the pull request). URLComponents/NSURLComponents/URLQueryItem init summaries and field taint are exact Foundation models, but ViewControllerStoredPropertyStep is a field-based, receiver-insensitive step for any UIViewController stored property, and the query copies stock path-injection.
    Real-world basis general. Foundation URLComponents/URLQueryItem (deep link query parsing is common in iOS apps) and UIKit view controller properties; no sample-app identifiers appear in the model logic.
    Stock overlap partial. Stock swift/path-injection and CustomUrlSchemes.qll already give the deep link sources; code search and the local pack show no URLComponents/URLQueryItem taint model upstream.
    Concerns, overlap and next steps

    False-positive concerns

    • The view controller step links any write of a stored property to any read through self, across instances and after overwrites.
    • Field taint marks host, scheme and path of a tainted URLComponents as tainted even when only the query is attacker controlled.

    Performance concerns

    • Property step joins every assignment with every read of each UIViewController stored property program-wide; small in scope but not receiver restricted.

    Heuristics used

    • Type names matched by string (URLComponents, URLQueryItem)
    • UIKit lifecycle approximated by a field-based property step

    What an upstream change would look like. Split: URLComponents models as a github/codeql swift/ql/lib patch (Url.qll style SummaryModelCsv + TaintInheritingContent, test in swift/ql/test/library-tests, swift/ql/lib/change-notes); property step in Community Packs.

    Before opening an upstream pull request

    • Put the models in the shared library instead of cloning swift/path-injection so every taint query benefits, and add a library flow test.
    • Check on a multi-project Swift corpus that the field taint adds no noisy alerts for other queries.
    • Drop or receiver-restrict the UIViewController stored-property step before any upstream use.
    • Confirm the Sequence first(where:) taint row is needed beside the stock CollectionElement row.

    Split note. The exact URLComponents/NSURLComponents/URLQueryItem models could be a separate github/codeql library patch; the UIViewController stored-property step is heuristic and stays experimental. The whole-PR recommendation is the conservative one.

    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/codeql or the Community Packs repository.

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

Metadata

Metadata

Labels

CWE-22data-extension-createenhancementprecision:mediumseverity:hightags:experimental

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions