Skip to content

Unified: Port UnsafeWebViewFetch query - #23217

Draft
geoffw0 wants to merge 11 commits into
github:mainfrom
geoffw0:unifiedwebview
Draft

geoffw0 wants to merge 11 commits into
github:mainfrom
geoffw0:unifiedwebview

Conversation

@geoffw0

@geoffw0 geoffw0 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Port the "Unsafe WebView fetch" query to unified, as unified/swift/unsafe-webview-fetch. Developed with Copilot + the porting skill + GPT-6.1 Sol High Effort. Some cleanup afterwards - in particular the way the original query handled baseURL wasn't great, it's considerably better now IMO. The four MISSING results in the test have been diagnosed and written up as issues (not fixed here).

DCA run to follow...

geoffw0 and others added 11 commits November 23, 2026 18:02
Create a byte-for-byte baseline from original Swift for the unified Swift port, including query help and samples. Adaptations follow separately.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copy the data flow configuration and query-specific models from the original Swift libraries without API or behavior adaptations. Keep source paths for provenance; the compiling port follows separately.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Use unified taint tracking and declarative UIWebView/WKWebView sink models. Preserve checks for nil, absent, and tainted base URLs, and point the inline-expectation test at the unified query.

The focused test passes with 12 result rows and no inline expectation failures. Retain six tainted-base-URL cases as MISSING for follow-up; this commit does not repair shared data flow or extraction.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Use node-based flowTo instead of flowToExpr, whose unified exprNode adapter is not yet implemented. This restores the UIWebView and WKWebView direct tainted-base-URL cases without changing shared data flow.

Preserve all 12 baseline result rows and add two detections. Four relative-URL and Data cases remain explicitly MISSING. Both the focused test and the related JavaScript-evaluation test pass without learning.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Explain that about:blank avoids local relative-URL resolution rather than promising to block absolute remote URLs. Keep navigation and content restrictions distinct from setting a trusted base URL.

Validate the help XML and local samples. The external Web View XSS reference was checked with the restricted link-checking agent and remains unchanged.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…ore readable and cleans up observeDiffInformedIncrementalMode).
@geoffw0 geoffw0 added no-change-note-required This PR does not need a change note Unified labels Nov 23, 2026
@github-actions

Copy link
Copy Markdown
Contributor

QHelp previews:

unified/ql/src/queries/security/CWE-079/UnsafeWebViewFetch.qhelp

Unsafe WebView fetch

Fetching data in a web view without restricting the base URL may allow an attacker to access sensitive local data, for example using file://. Data can then be extracted from the software using the URL of a machine under the attacker's control. More generally, an attacker may use a URL under their control as part of a cross-site scripting attack.

Recommendation

When loading HTML into a web view, always set the baseURL to an appropriate URL that you control, or to about:blank. Do not use nil, as this does not restrict URLs that can be resolved. Also do not use a baseURL that could itself be controlled by an attacker.

Example

In the following example, a call to UIWebView.loadHTMLString has the baseURL set to nil, which does not restrict URLs that can be resolved from within the web page.

let webview = UIWebView()

...

webview.loadHTMLString(htmlData, baseURL: nil) // BAD

To fix the problem, we set the baseURL to about:blank. This avoids resolving relative URLs against the application's local file system. A base URL is not a general navigation restriction: absolute remote URLs still need appropriate navigation and content controls.

let webview = UIWebView()

...

webview.loadHTMLString(htmlData, baseURL: URL(string: "about:blank")) // GOOD

References

This branch has not been deployed

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

Labels

documentation no-change-note-required This PR does not need a change note Unified

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant