From c5008b829dc779f0768089bff9b891fc76b11355 Mon Sep 17 00:00:00 2001 From: Tony <68118705+Legend-Master@users.noreply.github.com> Date: Fri, 10 Oct 2025 19:11:08 +0800 Subject: [PATCH] fix: skip empty script tag for CSP hash properly (#14274) * fix: skip empty script tag for CSP hash properly * add change file --------- Co-authored-by: Lucas Nogueira --- .changes/fix-csp-empty-selector.md | 5 +++++ crates/tauri-codegen/src/context.rs | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 .changes/fix-csp-empty-selector.md diff --git a/.changes/fix-csp-empty-selector.md b/.changes/fix-csp-empty-selector.md new file mode 100644 index 000000000..e40457b1e --- /dev/null +++ b/.changes/fix-csp-empty-selector.md @@ -0,0 +1,5 @@ +--- +"tauri-codegen": patch:bug +--- + +Do not hash empty scripts when generating the Content-Security-Policy SHA-256 hashes. diff --git a/crates/tauri-codegen/src/context.rs b/crates/tauri-codegen/src/context.rs index ed61481d2..9176aea64 100644 --- a/crates/tauri-codegen/src/context.rs +++ b/crates/tauri-codegen/src/context.rs @@ -45,7 +45,7 @@ pub struct ContextData { } fn inject_script_hashes(document: &NodeRef, key: &AssetKey, csp_hashes: &mut CspHashes) { - if let Ok(inline_script_elements) = document.select("script:not(empty)") { + if let Ok(inline_script_elements) = document.select("script:not(:empty)") { let mut scripts = Vec::new(); for inline_script_el in inline_script_elements { let script = inline_script_el.as_node().text_contents();