Skip to content

Commit 855ee44

Browse files
committed
fix(webkitgtk): mark custom URI schemes as CORS-enabled
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.
1 parent 0b1e2be commit 855ee44

2 files changed

Lines changed: 30 additions & 4 deletions

File tree

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
"wry": patch
3+
---
4+
5+
On Linux, mark custom URI schemes as CORS-enabled (in addition to
6+
secure) when registering them with webkit2gtk. webkit2gtk 2.46+ added a
7+
requirement that the scheme be in the CORS allow-list for the host's
8+
custom-scheme handler to be invoked for top-level navigations; without
9+
it webkit silently bypasses the handler and routes the request through
10+
the default network loader. Symptom for Tauri apps on Ubuntu 26.04 /
11+
Fedora 40+ / Arch rolling: the bundled UI fails to load and webview
12+
shows "Could not connect to localhost: Connection refused" because
13+
`tauri://localhost/` gets interpreted as `http://localhost:80/`.
14+
15+
The new call is a no-op on webkit2gtk ≤ 2.44 so the patch is safe on
16+
Ubuntu 22.04 / 24.04.

src/webkitgtk/web_context.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,23 @@ impl WebContextExt for super::WebContext {
133133
{
134134
self.register_custom_protocol(name.to_owned())?;
135135

136-
// Enable secure context
137-
self
136+
// Enable secure context + CORS for the scheme. webkit2gtk 2.46+
137+
// requires the scheme to be CORS-enabled or webkit silently bypasses
138+
// the registered handler and routes the request through the default
139+
// network loader. Symptom for callers using a custom scheme like
140+
// `tauri://localhost/`: the load lands as `http://localhost:80/` and
141+
// shows "Could not connect to localhost: Connection refused" instead
142+
// of the embedded asset.
143+
//
144+
// The CORS-enable call is a no-op on webkit2gtk ≤ 2.44 (Ubuntu 22.04
145+
// / 24.04) so it's safe to add unconditionally.
146+
let security_manager = self
138147
.os
139148
.context
140149
.security_manager()
141-
.ok_or(Error::MissingManager)?
142-
.register_uri_scheme_as_secure(name);
150+
.ok_or(Error::MissingManager)?;
151+
security_manager.register_uri_scheme_as_secure(name);
152+
security_manager.register_uri_scheme_as_cors_enabled(name);
143153

144154
self.os.context.register_uri_scheme(name, move |request| {
145155
#[cfg(feature = "tracing")]

0 commit comments

Comments
 (0)