From 3fe6af25f141fb4b1eb92c31ffb9939ac4ece3b0 Mon Sep 17 00:00:00 2001 From: Edouard Vanbelle Date: Tue, 14 Jul 2026 02:15:48 +0200 Subject: [PATCH] fix(loading): fix issue with sveltekit and scripts fix issues like: ``` Executing inline script violates the following Content Security Policy directive 'script-src 'self''. Either the 'unsafe-inline' keyword, a hash ('sha256-Vv9My0PApDW3C+xGLu9cH98KLrOg/Qhc7hlT1lK5tyM='), or a nonce ('nonce-...') is required to enable inline execution. The action has been blocked. ``` --- src/interfaces/web/mod.rs | 60 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) diff --git a/src/interfaces/web/mod.rs b/src/interfaces/web/mod.rs index 82dbc223..c0ca5eae 100644 --- a/src/interfaces/web/mod.rs +++ b/src/interfaces/web/mod.rs @@ -169,10 +169,43 @@ fn csp_hash(script: &str) -> String { /// Text content of every inline ``, and emit the +/// wrong hash — the real inline script then fails CSP with `script-src 'self'`. fn inline_scripts(html: &str) -> Vec<&str> { let mut scripts = Vec::new(); let mut cursor = 0; - while let Some(rel) = find_ci(&html[cursor..], "` in prose and would otherwise poison the + // scanner. Comment-nesting is not a spec concern. + let next_comment = find_ci(tail, "").map(|r| c + 4 + r + 3); + cursor = match end_rel { + Some(e) => cursor + e, + None => break, // unterminated comment; give up + }; + continue; + } + (Some(c), None) => { + let end_rel = find_ci(&tail[c + 4..], "-->").map(|r| c + 4 + r + 3); + cursor = match end_rel { + Some(e) => cursor + e, + None => break, + }; + continue; + } + (None, None) => break, + _ => {} // next thing is a real \n", + "\n", + ); + let scripts = inline_scripts(html); + assert_eq!(scripts, vec!["alert(1);", "boot();"]); + } + + #[test] + fn unterminated_comment_bails_out_gracefully() { + // Malformed input: `