Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

fix(app): keep the Windows widget origin inside the main webview

oxoxDev8d8068336ab1
diff --git a/crates/openhuman-app/src/external_navigation.rs b/crates/openhuman-app/src/external_navigation.rs
index 388a9a38d2..19f53cf9b1 100644
--- a/crates/openhuman-app/src/external_navigation.rs
+++ b/crates/openhuman-app/src/external_navigation.rs
@@ -30,6 +30,8 @@ const MAIN_WINDOW: &str = "main";
/// `windows_scheme` is `https` only when the window sets `useHttpsScheme`;
/// the other scheme or any other port is a different origin (e.g. a loopback
/// service) and is handed off;
+/// - `<windows_scheme>://ohwidget.localhost`, the widget sandbox origin on
+/// Windows;
/// - the dev server origin, passed as `dev_url` only under `tauri dev`.
pub(crate) fn navigation_handoff(
label: &str,
@@ -42,10 +44,15 @@ pub(crate) fn navigation_handoff(
}
// `Url` drops a scheme's default port, so `port()` is `None` only for the
// canonical origin.
- let is_windows_app_origin = url.scheme() == windows_scheme
- && url.host_str() == Some("tauri.localhost")
- && url.port().is_none();
- if is_windows_app_origin || dev_url.is_some_and(|dev| dev.origin() == url.origin()) {
+ let is_windows_local_origin = |host: &str| {
+ url.scheme() == windows_scheme && url.host_str() == Some(host) && url.port().is_none()
+ };
+ let is_windows_app_origin = is_windows_local_origin("tauri.localhost");
+ let is_windows_widget_origin = is_windows_local_origin("ohwidget.localhost");
+ if is_windows_app_origin
+ || is_windows_widget_origin
+ || dev_url.is_some_and(|dev| dev.origin() == url.origin())
+ {
return None;
}
Some(url.clone())
diff --git a/crates/openhuman-app/src/external_navigation_tests.rs b/crates/openhuman-app/src/external_navigation_tests.rs
index 4138e2e619..c5adfaf4d5 100644
--- a/crates/openhuman-app/src/external_navigation_tests.rs
+++ b/crates/openhuman-app/src/external_navigation_tests.rs
@@ -82,3 +82,20 @@ fn other_webviews_are_left_to_their_own_handlers() {
None
);
}
+
+#[test]
+fn widget_sandbox_origin_stays_in_the_main_webview() {
+ assert_eq!(
+ navigation_handoff("main", &url("http://ohwidget.localhost/proxy"), "http", None),
+ None
+ );
+ assert_eq!(
+ navigation_handoff("main", &url("ohwidget://localhost/proxy"), "http", None),
+ None
+ );
+ let other_port = url("http://ohwidget.localhost:8080/proxy");
+ assert_eq!(
+ navigation_handoff("main", &other_port, "http", None),
+ Some(other_port)
+ );
+}