From 41062461500410d07d02ab4a62af9e119562dbfb Mon Sep 17 00:00:00 2001 From: b84330808 Date: Fri, 30 Oct 2026 15:40:47 +0000 Subject: [PATCH 1/2] fix(cli): percent-decode request paths in the builtin dev server The builtin dev server, which `tauri dev` uses when `build.devUrl` is not set, looked files up with the raw request path. A request for `/my%20font.woff2` searched for a file literally named `my%20font.woff2`, did not find it and fell back to `index.html`, so files with spaces or non-ASCII characters in their names could not be loaded in development, while they work in production builds. Decode the path like the `tauri://` protocol does. `fs_read_scoped` still rejects decoded paths outside of the served directory. Fixes tauri-apps/tauri#12763 Co-Authored-By: Claude Opus 5.5 --- .changes/cli-dev-server-percent-decode.md | 6 +++ Cargo.lock | 1 + crates/tauri-cli/Cargo.toml | 1 + .../tauri-cli/src/dev/builtin_dev_server.rs | 44 ++++++++++++++++++- 4 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 .changes/cli-dev-server-percent-decode.md diff --git a/.changes/cli-dev-server-percent-decode.md b/.changes/cli-dev-server-percent-decode.md new file mode 100644 index 000000000000..909310867517 --- /dev/null +++ b/.changes/cli-dev-server-percent-decode.md @@ -0,0 +1,6 @@ +--- +"tauri-cli": patch:bug +"@tauri-apps/cli": patch:bug +--- + +Fix the builtin dev server serving `index.html` instead of files whose names contain spaces or non-ASCII characters, such as `my font.woff2`. The request path is now percent-decoded before looking up the file, as the `tauri://` protocol does in production builds. diff --git a/Cargo.lock b/Cargo.lock index 8ab3d3c2896c..1a2719e429cf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8467,6 +8467,7 @@ dependencies = [ "oxc_ast", "oxc_parser", "oxc_span", + "percent-encoding", "phf 0.14.0", "plist", "pretty_assertions", diff --git a/crates/tauri-cli/Cargo.toml b/crates/tauri-cli/Cargo.toml index b8a60c2347fb..51387e4f2b69 100644 --- a/crates/tauri-cli/Cargo.toml +++ b/crates/tauri-cli/Cargo.toml @@ -83,6 +83,7 @@ regex = "1" heck = "0.5" dialoguer = "0.12" url = { version = "2", features = ["serde"] } +percent-encoding = "2" os_pipe = "1" ignore = "0.4" ctrlc = "3" diff --git a/crates/tauri-cli/src/dev/builtin_dev_server.rs b/crates/tauri-cli/src/dev/builtin_dev_server.rs index 504440923e42..a96e434eb874 100644 --- a/crates/tauri-cli/src/dev/builtin_dev_server.rs +++ b/crates/tauri-cli/src/dev/builtin_dev_server.rs @@ -85,7 +85,10 @@ async fn handler(uri: Uri, headers: HeaderMap, state: State) -> imp } // Frontend files should not contain query parameters. This seems to be how Vite handles it. - let uri = uri.path(); + // The path is percent-encoded, decode it like the `tauri://` protocol does so files with spaces + // or non-ASCII characters in their names are found. + let path = percent_encoding::percent_decode_str(uri.path()).decode_utf8_lossy(); + let uri = path.as_ref(); let uri = if uri == "/" { uri @@ -368,4 +371,43 @@ mod tests { ); assert!(fs_read_scoped(inner.join("../secret.txt"), &inner).is_err()); } + + #[tokio::test] + async fn serves_percent_encoded_paths() { + let temp = tempfile::tempdir().unwrap(); + let temp = dunce::canonicalize(temp.path()).unwrap(); + let dir = temp.join("dist"); + std::fs::create_dir(&dir).unwrap(); + std::fs::write(dir.join("index.html"), "").unwrap(); + std::fs::write(dir.join("my font.woff2"), "font").unwrap(); + std::fs::write(dir.join("页面.css"), "css").unwrap(); + std::fs::write(temp.join("secret.txt"), "secret").unwrap(); + + let state = ServerState { + dir, + address: "127.0.0.1:1430".parse().unwrap(), + tx: channel(1).0, + }; + let get = |path: &str| { + let mut headers = HeaderMap::new(); + headers.insert(header::HOST, HeaderValue::from_static("127.0.0.1:1430")); + let response = handler(path.parse().unwrap(), headers, State(state.clone())); + async move { + let response = response.await.into_response(); + assert_eq!(response.status(), StatusCode::OK); + axum::body::to_bytes(response.into_body(), usize::MAX) + .await + .unwrap() + } + }; + + assert_eq!(get("/my%20font.woff2").await, "font"); + assert_eq!(get("/%E9%A1%B5%E9%9D%A2.css").await, "css"); + // decoded paths are still scoped to the served directory + assert_ne!(get("/%2E%2E/secret.txt").await, "secret"); + assert_ne!(get("/..%2Fsecret.txt").await, "secret"); + let secret = temp.join("secret.txt").display().to_string(); + let secret = percent_encoding::utf8_percent_encode(&secret, percent_encoding::NON_ALPHANUMERIC); + assert_ne!(get(&format!("/{secret}")).await, "secret"); + } } From 99c8733cdc32edbb7d9626cefea76c4f1278fb04 Mon Sep 17 00:00:00 2001 From: Amr Bashir Date: Sat, 31 Oct 2026 03:54:34 +0200 Subject: [PATCH 2/2] Update .changes/cli-dev-server-percent-decode.md --- .changes/cli-dev-server-percent-decode.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changes/cli-dev-server-percent-decode.md b/.changes/cli-dev-server-percent-decode.md index 909310867517..07792d54e5d2 100644 --- a/.changes/cli-dev-server-percent-decode.md +++ b/.changes/cli-dev-server-percent-decode.md @@ -3,4 +3,4 @@ "@tauri-apps/cli": patch:bug --- -Fix the builtin dev server serving `index.html` instead of files whose names contain spaces or non-ASCII characters, such as `my font.woff2`. The request path is now percent-decoded before looking up the file, as the `tauri://` protocol does in production builds. +Fix the builtin dev server serving `index.html` instead of files whose names contain spaces or non-ASCII characters, such as `my font.woff2`.