Skip to content

[bug] IPC fails in non-http protocol windows #11504

@luoffei

Description

@luoffei

Describe the bug

When a window is created using a non-http protocol (data:text/html,) the value of Origin is empty when calling the rust backend command. However, Origin is required when parsing the call request.

let url = Url::parse(
parts
.headers
.get("Origin")
.ok_or("missing Origin header")?
.to_str()
.map_err(|_| "Origin header value must be a string")?,
)
.map_err(|_| "Origin header is not a valid URL")?;

Reproduction

Create a window using a non-http protocol (data:text/html,)

let data_url = Url::parse("data:text/plain,Hello?World#").unwrap();
let _ = tauri::WebviewWindowBuilder::new(&app_handle, "example", tauri::WebviewUrl::CustomProtocol(data_url)).build();

Then the front end calls the rust backend command

const {open} = window.__TAURI__.shell;
open("https://github.com");

Expected behavior

No response

Full tauri info output

[✔] Environment
    - OS: Windows 10.0.22635 x86_64 (X64)
    ✔ WebView2: 130.0.2849.52
    ✔ MSVC: Visual Studio Community 2022
    ✔ rustc: 1.82.0 (f6e511eec 2024-10-15)
    ✔ cargo: 1.82.0 (8f40fc59f 2024-08-21)
    ✔ rustup: 1.27.1 (54dd3d00f 2024-04-24)
    ✔ Rust toolchain: stable-x86_64-pc-windows-msvc (environment override by RUSTUP_TOOLCHAIN)
    - node: 16.20.2
    - pnpm: 8.14.0
    - npm: 8.19.4

[-] Packages
    - tauri 🦀: 2.0.6
    - tauri-build 🦀: 2.0.2
    - wry 🦀: 0.46.2
    - tao 🦀: 0.30.3
    - tauri-cli 🦀: 2.0.1

[-] Plugins
    - tauri-plugin-fs 🦀: 2.0.2
    - tauri-plugin-autostart 🦀: 2.0.1
    - tauri-plugin-shell 🦀: 2.0.2
    - tauri-plugin-process 🦀: 2.0.1
    - tauri-plugin-single-instance 🦀: 2.0.1
    - tauri-plugin-notification 🦀: 2.0.1
    - tauri-plugin-http 🦀: 2.0.2

[-] App
    - build-type: bundle
    - CSP: unset
    - frontendDist: ../ui/dist
    - devUrl: http://localhost:8081/

Stack trace

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions