Skip to content

fix(webkitgtk): mark custom URI schemes as CORS-enabled#1725

Draft
sozenta wants to merge 1 commit into
tauri-apps:devfrom
Sozenta-Inc:feat/webkit-cors-enable
Draft

fix(webkitgtk): mark custom URI schemes as CORS-enabled#1725
sozenta wants to merge 1 commit into
tauri-apps:devfrom
Sozenta-Inc:feat/webkit-cors-enable

Conversation

@sozenta
Copy link
Copy Markdown

@sozenta sozenta commented May 6, 2026

Summary

On Linux, the registered handler for a custom URI scheme is silently bypassed by webkit2gtk 2.46+ for top-level navigations unless the scheme is also marked CORS-enabled. Adds the missing `register_uri_scheme_as_cors_enabled()` call alongside the existing `register_uri_scheme_as_secure()`.

Why

webkit2gtk 2.46 tightened security around custom URI schemes. The scheme registration via `webkit_web_context_register_uri_scheme()` no longer dispatches the handler for top-level navigations unless the scheme is also in the CORS allow-list. Without it, webkit silently routes the request through the default network loader.

For a Tauri app loading the bundled UI via `tauri://localhost/index.html`, this means the request lands at `http://localhost:80/\` (with nothing listening) and the webview shows webkit's standard "Could not connect to localhost: Connection refused" error page — the entire app appears broken to the user.

The new call is a no-op on webkit2gtk ≤ 2.44 (Ubuntu 22.04 / 24.04) so the fix is safe to ship across versions.

Validation

  • Reproduced: Ubuntu 26.04 LTS aarch64, webkit2gtk 2.52.0, Tauri 2.10.3 release build → webview shows the connection-error page
  • Patched: same setup → embedded UI loads correctly
  • The same Tauri app's dev mode (vite serving real HTTP on :5173) was always working, isolating the bug to the custom-scheme path on Linux release builds
  • Mac (WKWebView) / Windows (WebView2) untouched

Test plan

  • CI: existing wry tests pass
  • Reviewer (Ubuntu 22.04 / 24.04): confirm the extra CORS-enable call is harmless on webkit2gtk ≤ 2.44 (the underlying C function is a no-op there per the webkit2gtk source)
  • Reviewer (any Linux with webkit2gtk ≥ 2.46): confirm a sample Tauri app's release build that previously failed with the localhost error now loads
  • Reviewer (Mac / Windows): no regression — the patch only touches `src/webkitgtk/`

Notes

  • The CORS-enable call comes from the existing `webkit2gtk = "=2.0.2"` Rust binding. No new dependency, no feature flag.
  • The full integration that proved this out is at https://github.com/Sozenta-Inc/veya/pull/17 (vendored wry + workspace patch + repro doc) so we can drop the local fork once a wry release with this patch lands.

Draft until reviewers confirm + I respond to feedback.

webkit2gtk 2.46 added a requirement that custom URI schemes registered
via `webkit_web_context_register_uri_scheme()` must ALSO be in the
CORS allow-list (`webkit_security_manager_register_uri_scheme_as_cors_enabled()`)
for the host's handler to be invoked on top-level navigations.

Previously wry only called `register_uri_scheme_as_secure()`. On
webkit2gtk ≤ 2.44 (Ubuntu 22.04 / 24.04) this was sufficient. On
webkit2gtk 2.46+ (Ubuntu 26.04, Fedora 40+, Arch rolling) webkit
silently bypasses the handler and falls through to the default
network loader.

Symptom for Tauri apps: the bundled UI loaded via `tauri://localhost/`
fails to render and the webview shows "Could not connect to localhost:
Connection refused" because the request lands at `http://localhost:80/`
where nothing's listening.

The CORS-enable call is a no-op on older webkit2gtk so the patch is
safe across versions.

Verified end-to-end on Ubuntu 26.04 LTS aarch64 with webkit2gtk
2.52.0: before, custom-scheme load shows the connection-error page;
after, the embedded UI loads correctly.
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 8, 2026

Package Changes Through 855ee44

There are 1 changes which include wry with minor

Planned Package Versions

The following package releases are the planned based on the context of changes in this pull request.

package current next
wry 0.55.1 0.56.0

Add another change file through the GitHub UI by following this link.


Read about change files or the docs at github.com/jbolda/covector

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.

2 participants