From 0d529c949749aaf493e53d93e507eff529328e03 Mon Sep 17 00:00:00 2001 From: Lucas Nogueira Date: Tue, 2 May 2023 10:01:57 -0300 Subject: [PATCH] fix(core): IPC remote domain check bypassed by isolation iframe usage (#6691) --- core/tauri/src/manager.rs | 11 +++++++++++ core/tauri/src/pattern.rs | 22 +++++++++++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/core/tauri/src/manager.rs b/core/tauri/src/manager.rs index 15521061fc52..48a521937887 100644 --- a/core/tauri/src/manager.rs +++ b/core/tauri/src/manager.rs @@ -1154,9 +1154,20 @@ impl WindowManager { } } + #[cfg(feature = "isolation")] + let pattern = self.pattern().clone(); let current_url_ = pending.current_url.clone(); let navigation_handler = pending.navigation_handler.take(); pending.navigation_handler = Some(Box::new(move |url| { + // always allow navigation events for the isolation iframe and do not emit them for consumers + #[cfg(feature = "isolation")] + if let Pattern::Isolation { schema, .. } = &pattern { + if url.scheme() == schema + && url.domain() == Some(crate::pattern::ISOLATION_IFRAME_SRC_DOMAIN) + { + return true; + } + } *current_url_.lock().unwrap() = url.clone(); if let Some(handler) = &navigation_handler { handler(url) diff --git a/core/tauri/src/pattern.rs b/core/tauri/src/pattern.rs index e78bc2b8b661..2f97c54cc3f7 100644 --- a/core/tauri/src/pattern.rs +++ b/core/tauri/src/pattern.rs @@ -15,7 +15,7 @@ use tauri_utils::assets::{Assets, EmbeddedAssets}; pub const ISOLATION_IFRAME_SRC_DOMAIN: &str = "localhost"; /// An application pattern. -#[derive(Debug, Clone)] +#[derive(Debug)] pub enum Pattern { /// The brownfield pattern. Brownfield(PhantomData), @@ -38,6 +38,26 @@ pub enum Pattern { }, } +impl Clone for Pattern { + fn clone(&self) -> Self { + match self { + Self::Brownfield(a) => Self::Brownfield(*a), + #[cfg(feature = "isolation")] + Self::Isolation { + assets, + schema, + key, + crypto_keys, + } => Self::Isolation { + assets: assets.clone(), + schema: schema.clone(), + key: key.clone(), + crypto_keys: crypto_keys.clone(), + }, + } + } +} + /// The shape of the JavaScript Pattern config #[derive(Debug, Serialize)] #[serde(rename_all = "lowercase", tag = "pattern")]