fix: check if url local with platform custom protocol, closes #7176 (#7202)

* fix: check if url local with platform custom protocol, closes #7176

* Update core/tauri/src/window.rs
This commit is contained in:
Amr Bashir 2023-06-14 19:39:38 +03:00 committed by GitHub
parent b66e7d60f2
commit 0fa0fa4ccf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 7 deletions

View File

@ -377,13 +377,17 @@ impl<R: Runtime> WindowManager<R> {
pub(crate) fn get_url(&self) -> Cow<'_, Url> {
match self.base_path() {
AppUrl::Url(WindowUrl::External(url)) => Cow::Borrowed(url),
#[cfg(windows)]
_ => Cow::Owned(Url::parse("https://tauri.localhost").unwrap()),
#[cfg(not(windows))]
_ => Cow::Owned(Url::parse("tauri://localhost").unwrap()),
_ => self.protocol_url(),
}
}
pub(crate) fn protocol_url(&self) -> Cow<'_, Url> {
#[cfg(any(window, target_os = "android"))]
return Cow::Owned(Url::parse("https://tauri.localhost").unwrap());
#[cfg(not(any(window, target_os = "android")))]
Cow::Owned(Url::parse("tauri://localhost").unwrap())
}
fn csp(&self) -> Option<Csp> {
if cfg!(feature = "custom-protocol") {
self.inner.config.tauri.security.csp.clone()

View File

@ -1653,13 +1653,18 @@ impl<R: Runtime> Window<R> {
self.current_url = url;
}
fn is_local_url(&self, current_url: &Url) -> bool {
self.manager.get_url().make_relative(current_url).is_some() || {
let protocol_url = self.manager.protocol_url();
current_url.scheme() == protocol_url.scheme() && current_url.domain() == protocol_url.domain()
}
}
/// Handles this window receiving an [`InvokeMessage`].
pub fn on_message(self, payload: InvokePayload) -> crate::Result<()> {
let manager = self.manager.clone();
let current_url = self.url();
let config_url = manager.get_url();
let is_local =
config_url.make_relative(&current_url).is_some() || current_url.scheme() == "tauri";
let is_local = self.is_local_url(&current_url);
let mut scope_not_found_error_message =
ipc_scope_not_found_error_message(&self.window.label, current_url.as_str());