Skip to content

[UPDATE QUERY] Swift: report local user input reaching swift/unsafe-webview-fetch sinks - #333

Draft
felickz with Copilot wants to merge 3 commits into
mainfrom
copilot/swiftquery-updatexss-response-splitting
Draft

felickz with Copilot wants to merge 3 commits into
mainfrom
copilot/swiftquery-updatexss-response-splitting

Conversation

Copilot AI commented Oct 31, 2026 •

Copy link
Copy Markdown

📝 Query Update

  • Query File: languages/swift/custom/src/UnsafeWebViewFetchLocalInput/UnsafeWebViewFetchLocalInput.ql (complements upstream swift/unsafe-webview-fetch)
  • Language: swift
  • Update Type: enhanced detection (missing source)

🎯 Changes

What Changed

  • Query. Adds swift/custom/unsafe-webview-fetch-local-input. It uses upstream swift/unsafe-webview-fetch unchanged, with the same sinks, barriers, extra flow steps and base-URL reporting rules. The only difference is that its source is LocalFlowSource instead of RemoteFlowSource.
  • Library (UnsafeWebViewFetchLocalInput.qll). Holds the config, the flow module and an unsafeWebViewFetchLocalInput(sink, message) predicate. The query and the test share this predicate.
  • New Swift packs. languages-swift-custom-src and languages-swift-custom-test. This repo had no Swift directory before.
  • Docs. Query help (.md) and a newQuery change note.

Why This Change

The issue guessed that UITextField.text isn't modeled. It already is, in swift-all frameworks/UIKit/UITextField.qll, but as a local source. swift/unsafe-webview-fetch only accepts RemoteFlowSource, so local input never reaches its sinks. Swift has no threat-model setting that could turn local sources on, so changing configuration can't close the gap. A custom query has to change the source set.

Remote sources are left out on purpose so this query's alerts don't overlap with the standard query's.

Impact

New alerts on UIWebView/WKWebView loadHTMLString and load(...) calls when local user input reaches them and the base URL is nil, missing, or built from that input. Results from the standard query are unchanged.

🔍 Before vs. After

The pattern from iGoat-Swift, reduced to a test case:

let webText = "Welcome ... \(textField.text ?? "")"
webview.loadHTMLString(webText, baseURL: nil)

Previous Behavior

No alert. UITextField.text is a LocalFlowSource, which swift/unsafe-webview-fetch ignores.

New Behavior

Reported by swift/custom/unsafe-webview-fetch-local-input: "Local user input is used in a WebView fetch without restricting the base URL."

🧪 Testing

test/UnsafeWebViewFetchLocalInput/ is an inline-expectation test: MakeTest with an empty .expected.

  • Positive cases:

    • the reduced iGoat case
    • string concatenation into WKWebView
    • a base URL built from the input
    • the UITextFieldDelegate replacement-string parameter
  • Negative cases:

    • an about:blank base URL
    • constant HTML
    • placeholder, which isn't a source
    • remote input, which the standard query already reports
  • New/updated test cases added

  • All tests pass. The test has not been run: the Swift extractor only works on macOS, so a macOS run of codeql test run -- UnsafeWebViewFetchLocalInput/ is required.

  • Regression tests validated

  • No unintended side effects

📊 Impact Analysis

  • Compatibility: backward compatible (new custom query; upstream query untouched)
  • Performance: neutral (same sinks and steps as upstream, with a different source set)
  • Accuracy: better recall for UI-input XSS. Precision is set to medium because injecting through the device's own UI is lower risk than remote input.

📋 Checklist

  • Query compiles without errors
  • Documentation updated
  • Tests updated with new expectations
  • Metadata updated if needed

🔗 References

Co-authored-by: felickz <1760475+felickz@users.noreply.github.com>
Copilot AI changed the title [WIP] Enhance detection coverage for CWE-79 XSS in Swift [UPDATE QUERY] Swift: report local user input reaching swift/unsafe-webview-fetch sinks Oct 31, 2026
Copilot AI requested a review from felickz October 31, 2026 04:49
@felickz
felickz requested a balanced review from Copilot November 2, 2026 18:37

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The documented Swift-only pack installation command fails because the installer’s language allowlist does not include Swift.

1 open issue
What changed in this PR

Adds a custom Swift query to detect local user input reaching unsafe WebView fetches, complementing the upstream remote-input query without changing it.

Changes:

  • Adds local-source taint tracking using upstream sinks, barriers, and base-URL reporting rules.
  • Introduces Swift source and test packs with positive and negative inline-expectation cases.
  • Adds query help and a change note. Swift tests still require a macOS run.
File Description
languages/​swift/​custom/​test/​UnsafeWebViewFetchLocalInput/​UnsafeWebViewFetchLocalInputTest.ql Checks results against inline expectations.
languages/​swift/​custom/​test/​UnsafeWebViewFetchLocalInput/​UnsafeWebViewFetchLocalInputTest.expected Expects no inline-expectation mismatches.
languages/​swift/​custom/​test/​UnsafeWebViewFetchLocalInput/​test.swift Adds vulnerable and safe WebView test cases.
languages/​swift/​custom/​test/​qlpack.yml Defines the Swift test pack.
languages/​swift/​custom/​src/​UnsafeWebViewFetchLocalInput/​UnsafeWebViewFetchLocalInput.qll Shares local-input tracking and reporting logic.
languages/​swift/​custom/​src/​UnsafeWebViewFetchLocalInput/​UnsafeWebViewFetchLocalInput.ql Defines the security query and path results.
languages/​swift/​custom/​src/​UnsafeWebViewFetchLocalInput/​UnsafeWebViewFetchLocalInput.md Documents detection and remediation.
languages/​swift/​custom/​src/​qlpack.yml Defines the Swift query pack.
languages/​swift/​custom/​src/​change-notes/​2026-10-31-unsafe-webview-fetch-local-input.md Announces the new query.

Review effort: Balanced

Comment thread languages/swift/custom/src/qlpack.yml Resolved
Co-authored-by: felickz <1760475+felickz@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

3 participants