Skip to content

[Query Update]: CWE-79 MEDIUM - Swift: extend XSS, response splitting and output neutralization coverage (swift/unsafe-webview-fetch) #283

Open

Description

@felickz

Query File Path

swift/unsafe-webview-fetch

Update Type

Enhanced detection coverage

Issue Description

AI Scan reported 1 medium-severity CWE-79 (xss response splitting) finding(s) in Swift public synthetic repositories that the baseline CodeQL default-setup scan did not report. Gap categories: missing-source. Existing queries considered: swift/unsafe-webview-fetch.

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

  • Text from a UI text field concatenated into HTML for loadHTMLString is not reported, likely because UITextField text is not a modeled source.

Linked findings (gap-key: swift/query-update/xss-response-splitting)

Repo CWE Severity AI scan alert Summary
iGoat-Swift CWE-79 medium https://github.com/codeql-forks-felickz/iGoat-Swift/security/code-scanning/6 Text entered by the user is concatenated into an HTML document and passed to loadHTMLString without HTML encoding or script restrictions.

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 (1)

Patterns in this gap

  • webview-html-ui-input (1 finding), for example iGoat-Swift iGoat-Swift/iGoat-Swift/Source/Exercises/Injection Flaws/XSS/CrossSiteScriptingExerciseVC.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/Injection Flaws/XSS/CrossSiteScriptingExerciseVC.swift:8 (CWE-79, medium)
  • AI Scan alert: https://github.com/codeql-forks-felickz/iGoat-Swift/security/code-scanning/6
  • AI Scan message: Text entered by the user is concatenated into an HTML document and passed to loadHTMLString without HTML encoding or script restrictions.
  • Context for the agent: A Swift view controller concatenates text from a text field into an HTML string passed to loadHTMLString. CodeQL would need UI text field input as a source for the web view XSS sink.
  • Why CodeQL appears to miss it: missing-source: Text from a UI text field concatenated into HTML for loadHTMLString is not reported, likely because UITextField text is not a modeled source.
  • Existing CodeQL queries considered: swift/unsafe-webview-fetch
  • Recommended action from the comparison: extend-existing-query (classification confidence: medium)

Proposed Solution

  1. Reproduce each linked finding with a minimal synthetic test case and confirm the baseline result.
  2. Identify the missing source, sink, summary or scope condition and extend the smallest model or query that fixes it.
  3. Add positive and negative tests and a change note.
  4. 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/79.html

Code of Conduct

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

Activity

  1. added
    enhancement
    CWE-79
    severity:medium
    on Oct 31, 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.

    Linked pull request: #333

    Why. The PR reruns the stock unsafe-webview-fetch sinks with LocalFlowSource, not RemoteFlowSource. Local sources include the stock contentsOfFile heuristic, so bundled HTML read with String(contentsOfFile:) and loaded with a nil baseURL would alert, and typed text is the user's own input (self-XSS). Sibling stock queries use FlowSource, but changing this high-precision stock query would affect all users. Fit for experimental Community Packs.

    Change Patch to an existing query or library
    Target swift/unsafe-webview-fetch: stock sources are RemoteFlowSource only; PR reruns the stock sinks with LocalFlowSource
    Precision assessed medium (declared medium in the pull request). Flow uses stock sinks, barriers and steps, but sources are every LocalFlowSource, including the stock contentsOfFile heuristic and typed UI text. Bundled HTML templates and editor previews would alert; the tests cover neither.
    Real-world basis partial. UITextField/UITextView input into WKWebView and UIWebView loadHTMLString is a public API pattern, but typed text is the user's own input (self-XSS) and the only motivating case is a training XSS exercise.
    Stock overlap partial. Reuses stock UnsafeWebViewFetchExtensions sinks, barriers and steps; only the source class differs. Sibling stock queries (unsafe-js-eval, sql-injection) use FlowSource. Checked local swift-all 6.8.3.
    Concerns, overlap and next steps

    False-positive concerns

    • Bundled HTML read with String(contentsOfFile:) (a stock local source heuristic) then passed to loadHTMLString with a nil baseURL is reported
    • Markdown, note or HTML editor previews that render the user's own typed text in a web view are reported although only the user can inject

    Heuristics used

    • inherits the stock contentsOf initializer heuristic through LocalFlowSource
    • source is every LocalFlowSource, not only UI text input

    What an upstream change would look like. Community Packs swift/src/<category>/UnsafeWebViewFetchLocalInput.ql reusing the stock extensions, sources narrowed to UITextField/UITextView text; tests in swift/test/. A github/codeql patch (FlowSource in UnsafeWebViewFetchQuery.qll) would change a stock query for all users.

    Before opening an upstream pull request

    • Narrow sources to UI text input, or add a negative test proving bundled contentsOfFile HTML is not reported
    • Add a true positive from a real, non-training project (Community Packs requirement)
    • Agree with maintainers whether typed text should be a source for this stock query before any github/codeql patch

    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-79enhancementprecision:mediumquery-updateseverity:mediumtags:experimental

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions