Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions runtime/src/app_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,14 @@ fn is_local_host(host: Option<&str>) -> bool {
matches!(host, Some("localhost") | Some("127.0.0.1") | Some("::1") | Some("[::1]"))
}

fn is_tauri_asset_host(host: Option<&str>) -> bool {
matches!(host, Some("tauri.localhost"))
}

fn is_tauri_asset_url(url: &tauri::Url) -> bool {
matches!(url.scheme(), "http" | "https") && is_tauri_asset_host(url.host_str())
}

fn is_local_http_url(url: &tauri::Url) -> bool {
matches!(url.scheme(), "http" | "https") && is_local_host(url.host_str())
}
Expand All @@ -220,6 +228,10 @@ fn should_open_in_system_browser<R: tauri::Runtime>(webview: &tauri::Webview<R>,
_ => return false,
}

if is_tauri_asset_url(url) {
return false;
}

if let Some(approved_app_url) = APPROVED_APP_URL.lock().unwrap().as_ref() {
if same_origin(approved_app_url, url) {
return false;
Expand Down Expand Up @@ -942,6 +954,36 @@ fn validate_shortcut_syntax(shortcut: &str) -> bool {
has_key
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn tauri_localhost_is_tauri_asset_url() {
let https_url = tauri::Url::parse("https://tauri.localhost/index.html").unwrap();
let http_url = tauri::Url::parse("http://tauri.localhost/index.html").unwrap();

assert!(is_tauri_asset_url(&https_url));
assert!(is_tauri_asset_url(&http_url));
}

#[test]
fn localhost_app_url_is_not_tauri_asset_url() {
let url = tauri::Url::parse("http://localhost:12345/").unwrap();

assert!(!is_tauri_asset_url(&url));
assert!(is_local_http_url(&url));
}

#[test]
fn external_url_is_not_internal_url() {
let url = tauri::Url::parse("https://example.com/").unwrap();

assert!(!is_tauri_asset_url(&url));
assert!(!is_local_http_url(&url));
}
}

fn set_pdfium_path<R: tauri::Runtime>(path_resolver: &PathResolver<R>) {
let resource_dir = match path_resolver.resource_dir() {
Ok(path) => path,
Expand Down