The design language that makes your AI harness better at design.
JavaScript
Fix CSP meta patch hiding a separator after an unknown &name; reference (#1145)
Paul Bakausea69c18d9f53
diff --git a/Cargo.lock b/Cargo.lockindex 33cfb61e5..895045bd1 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -717,6 +717,7 @@ dependencies = ["impeccable-context","impeccable-core","impeccable-hook",+ "markup5ever","once_cell","regex","serde",diff --git a/crates/live/Cargo.toml b/crates/live/Cargo.tomlindex 041f228fd..9e4f58326 100644--- a/crates/live/Cargo.toml+++ b/crates/live/Cargo.toml@@ -18,3 +18,4 @@ sha2 = "0.10"ureq = { version = "2", default-features = false, features = ["tls", "json"] }sha1 = "0.10"getrandom = "0.2"+markup5ever = "0.39"diff --git a/crates/live/src/inject/tag_strategy.rs b/crates/live/src/inject/tag_strategy.rsindex 4b4d2424c..66f3bd44f 100644--- a/crates/live/src/inject/tag_strategy.rs+++ b/crates/live/src/inject/tag_strategy.rs@@ -3,6 +3,7 @@//! meta patch/revert.use crate::util::{base64_decode, base64_encode, encode_uri_component};+use markup5ever::data::NAMED_ENTITIES;use once_cell::sync::Lazy;use regex::{Regex, RegexBuilder};@@ -244,11 +245,22 @@ fn get_attr(attrs: &str, name: &str) -> Option<Attr> {best.map(|(_, a)| a)}-/// Length of the HTML character reference at the start of `s` (which starts-/// with `&`), if one starts there. A numeric reference may omit its `;`, as-/// browsers read it; a named one counts only with its `;`.-fn reference_len(s: &str) -> Option<usize> {- let b = s.as_bytes();+/// How a browser reads the `&` at the start of `tail` inside an attribute+/// value, following the HTML tokenizer's character reference state.+enum Reference {+ /// Not a reference: the `&` is a literal character and what follows is+ /// read as ordinary text, so a `;` after `&bogus` still separates.+ Literal,+ /// A numeric reference, or a named one that decodes to one ASCII+ /// character: the character and the reference's length in bytes.+ Char(char, usize),+ /// A real named reference that decodes to anything else (`©`).+ /// A CSP is ASCII, so the patch only needs to know it is one unit.+ Opaque(usize),+}++fn read_reference(tail: &str) -> Reference {+ let b = tail.as_bytes();if b.get(1) == Some(&b'#') {let hex = matches!(b.get(2), Some(b'x' | b'X'));let start = if hex { 3 } else { 2 };@@ -263,81 +275,65 @@ fn reference_len(s: &str) -> Option<usize> {i += 1;}if i == start {- return None;+ return Reference::Literal;}+ let digits = &tail[start..i];+ // A numeric reference may omit its `;`, as browsers read it.if b.get(i) == Some(&b';') {i += 1;}- Some(i)- } else {- let mut i = 1;- while i < b.len() && b[i].is_ascii_alphanumeric() {- i += 1;+ let code = if hex {+ u32::from_str_radix(digits, 16).ok()+ } else {+ digits.parse::<u32>().ok()+ };+ let ch = code+ .filter(|c| *c != 0)+ .and_then(char::from_u32)+ .unwrap_or('\u{FFFD}');+ return Reference::Char(ch, i);+ }+ // Named: the longest name in the HTML table that the text spells. Names+ // are alphanumeric, ending in `;` except for the legacy ones (`&`,+ // `©`). The table also holds every prefix of a name mapped to (0, 0);+ // those are not references.+ let run = 1 + b[1..]+ .iter()+ .take_while(|c| c.is_ascii_alphanumeric())+ .count();+ // Walk forward one byte at a time. Every prefix of a name is in the+ // table, so the first miss ends the search: an unknown name costs one+ // lookup, not one per byte of the text after it.+ let mut found = None;+ for end in 2..=run {+ let Some(&value) = NAMED_ENTITIES.get(&tail[1..end]) else {+ break;+ };+ if value != (0, 0) {+ found = Some((value, end));}- if i == 1 || b.get(i) != Some(&b';') {- return None;+ if end == run && b.get(run) == Some(&b';') {+ if let Some(&value) = NAMED_ENTITIES.get(&tail[1..=run]) {+ if value != (0, 0) {+ found = Some((value, run + 1));+ }+ }}- Some(i + 1)}-}--/// The named references that decode to ASCII, the only characters a CSP is-/// made of. Any other `&name;` is kept as one opaque unit: it may be a real-/// reference (`©`) or literal text (`&bogus;`), and telling them apart-/// takes the full HTML table. Treating it as text inside a source means an-/// insertion never lands between its name and its `;`.-const ASCII_NAMED_REFERENCES: [(&str, char); 29] = [- ("amp", '&'),- ("quot", '"'),- ("apos", '\''),- ("lt", '<'),- ("gt", '>'),- ("semi", ';'),- ("colon", ':'),- ("comma", ','),- ("period", '.'),- ("sol", '/'),- ("bsol", '\\'),- ("Tab", '\t'),- ("NewLine", '\n'),- ("ast", '*'),- ("plus", '+'),- ("lowbar", '_'),- ("equals", '='),- ("quest", '?'),- ("num", '#'),- ("percnt", '%'),- ("excl", '!'),- ("commat", '@'),- ("dollar", '$'),- ("lpar", '('),- ("rpar", ')'),- ("lsqb", '['),- ("rsqb", ']'),- ("lcub", '{'),- ("rcub", '}'),-];--/// `tail` starts with `&`. Returns the decoded char and the reference length-/// for numeric references and the names in `ASCII_NAMED_REFERENCES`.-fn decode_reference(tail: &str) -> Option<(char, usize)> {- let len = reference_len(tail)?;- let body = tail[1..len].trim_end_matches(';');- let ch = if let Some(num) = body.strip_prefix('#') {- let code = match num.strip_prefix(['x', 'X']) {- Some(hex) => u32::from_str_radix(hex, 16).ok(),- None => num.parse::<u32>().ok(),- };- code.filter(|c| *c != 0)- .and_then(char::from_u32)- .unwrap_or('\u{FFFD}')- } else {- ASCII_NAMED_REFERENCES- .iter()- .find(|(name, _)| *name == body)?- .1+ let Some(((first, second), len)) = found else {+ return Reference::Literal;};- Some((ch, len))+ // In an attribute, a legacy name followed by `=` or an alphanumeric is+ // not decoded (`?a&b=1` keeps its text).+ if !tail[..len].ends_with(';')+ && matches!(b.get(len), Some(c) if *c == b'=' || c.is_ascii_alphanumeric())+ {+ return Reference::Literal;+ }+ match char::from_u32(first) {+ Some(ch) if second == 0 && ch.is_ascii() => Reference::Char(ch, len),+ _ => Reference::Opaque(len),+ }}/// One decoded character of a raw attribute value and the raw bytes it came@@ -346,7 +342,7 @@ struct Unit {ch: char,start: usize,end: usize,- /// An `&name;` outside `ASCII_NAMED_REFERENCES`, read as its raw text.+ /// A named reference that does not decode to ASCII, read as its raw text.opaque: bool,}@@ -356,12 +352,10 @@ fn decode_units(raw: &str) -> Vec<Unit> {while i < raw.len() {let tail = &raw[i..];let (ch, len, opaque) = if tail.starts_with('&') {- match decode_reference(tail) {- Some((ch, len)) => (ch, len, false),- None => match reference_len(tail) {- Some(len) if tail.as_bytes()[1] != b'#' => ('\u{FFFD}', len, true),- _ => ('&', 1, false),- },+ match read_reference(tail) {+ Reference::Char(ch, len) => (ch, len, false),+ Reference::Opaque(len) => ('\u{FFFD}', len, true),+ Reference::Literal => ('&', 1, false),}} else {let c = tail.chars().next().unwrap();@@ -378,8 +372,8 @@ fn decode_units(raw: &str) -> Vec<Unit> {out}-/// The value a browser hands the CSP parser, for the references-/// `decode_reference` knows; anything else passes through unchanged.+/// The value a browser hands the CSP parser, with references that decode to+/// non-ASCII kept as their raw text.#[cfg(test)]fn decode_html_attr_value(value: &str) -> String {let mut out = String::with_capacity(value.len());@@ -469,13 +463,16 @@ fn append_origin_to_directive(raw: &str, directive: &str, source: &str, quote: &_ => "",};// A trailing `c` or `&` would take the new `;` as its terminator- // and swallow the separator; a space ends the reference first.- let tail = base.rfind('&').map(|i| &base[i + 1..]).unwrap_or(" ");- let gap = if !tail.is_empty() && tail.bytes().all(|b| b.is_ascii_alphanumeric() || b == b'#') {- " "- } else {- ""- };+ // and swallow the separator; a space ends the reference first. A+ // trailing `&b` cannot: `&b;` is no reference, so its `;` separates.+ let swallows = base.rfind('&').is_some_and(|i| {+ let probe = format!("{};", &base[i..]);+ match read_reference(&probe) {+ Reference::Char(_, len) | Reference::Opaque(len) => len == probe.len(),+ Reference::Literal => false,+ }+ });+ let gap = if swallows { " " } else { "" };format!("{}{}; {} {} {}",base,@@ -811,6 +808,86 @@ mod tests {}}+ #[test]+ fn unknown_named_reference_keeps_its_semicolon_as_a_separator() {+ // `&b;` is not in the HTML table, so a browser reads `&b` as text and+ // the `;` ends img-src. Reading it as one unit used to hide the+ // separator: blob: landed in script-src and a second script-src was+ // added.+ let html = "<meta http-equiv=\"Content-Security-Policy\" content=\"img-src https://a.example/?a&b; script-src 'self'\">";+ let patched = patch_csp_meta(html, 8412);+ assert!(+ patched.contains("content=\"img-src https://a.example/?a&b blob:; script-src 'self' http://localhost:8412 'wasm-unsafe-eval'; connect-src 'self' http://localhost:8412\""),+ "{patched}"+ );+ assert_eq!(+ browser_policy(&patched),+ "img-src https://a.example/?a&b blob:; script-src 'self' http://localhost:8412 'wasm-unsafe-eval'; connect-src 'self' http://localhost:8412"+ );+ assert_eq!(revert_csp_meta(&patched), html);+ assert_eq!(patch_csp_meta(&revert_csp_meta(&patched), 8412), patched);+ }++ #[test]+ fn named_references_follow_the_html_table() {+ // Every name that decodes to ASCII is read, not only the common ones.+ assert_eq!(+ decode_html_attr_value("|`["&*"),+ "|`[\"&*"+ );+ // Legacy names without `;` decode, except before `=` or an+ // alphanumeric, which in an attribute keeps the text.+ assert_eq!(+ decode_html_attr_value("& x < &b &=1 >"),+ "& x < &b &=1 >"+ );+ // A real non-ASCII reference hides no separator: `∉` is one+ // character, so script-src here is a source of img-src and the patch+ // adds a real script-src. `¬it;` is the legacy `¬` before an+ // alphanumeric, so it stays text and its `;` separates.+ for (csp, expect) in [+ (+ "img-src a∉ script-src 'self'",+ "img-src a∉ script-src 'self' blob:; script-src 'self' http://localhost:9797 'wasm-unsafe-eval'; connect-src 'self' http://localhost:9797",+ ),+ (+ "img-src a¬it; script-src 'self'",+ "img-src a¬it blob:; script-src 'self' http://localhost:9797 'wasm-unsafe-eval'; connect-src 'self' http://localhost:9797",+ ),+ ] {+ let html = format!("<meta http-equiv=\"Content-Security-Policy\" content=\"{csp}\">");+ let patched = patch_csp_meta(&html, 9797);+ assert!(patched.contains(&format!("content=\"{expect}\"")), "{patched}");+ assert_eq!(revert_csp_meta(&patched), html);+ }+ }++ #[test]+ fn trailing_text_that_cannot_take_a_semicolon_gets_no_gap() {+ for (csp, base) in [+ // `&b;` is no reference, so the added `;` separates on its own.+ (+ "default-src https://a.example/?a&b",+ "default-src https://a.example/?a&b",+ ),+ // `©` is one, so it needs the space.+ (+ "default-src https://a.example/©",+ "default-src https://a.example/© ",+ ),+ ] {+ let html = format!("<meta http-equiv=\"Content-Security-Policy\" content=\"{csp}\">");+ let patched = patch_csp_meta(&html, 9797);+ assert!(+ patched.contains(&format!(+ "content=\"{base}; script-src 'self' http://localhost:9797 'wasm-unsafe-eval';"+ )),+ "{patched}"+ );+ assert_eq!(revert_csp_meta(&patched), html);+ }+ }+#[test]fn patch_then_revert_is_byte_identical() {let cases = [diff --git a/docs/CLI-CONTRACT.md b/docs/CLI-CONTRACT.mdindex f97fd8d92..4ac98839a 100644--- a/docs/CLI-CONTRACT.md+++ b/docs/CLI-CONTRACT.md@@ -1615,7 +1615,7 @@ Source traits by target file extension (first registry entry claiming the ext; d````open/close` = `<!--`/`-->` for `html`, `{/*`/`*/}` for `jsx`. Line endings normalized to the file's dominant one. `insertBefore`: inserted at LAST occurrence of anchor. `insertAfter`: after FIRST occurrence, preserving an existing newline right after the anchor. Anchor missing → content unchanged → result `{file, error:'insertion_point_not_found', anchor}`. Removal regex handles both comment styles, indent-preserving. Repeat inject first removes any old block and reverts CSP.-CSP meta patch: for `<meta http-equiv="Content-Security-Policy" content="…">` (not already carrying `data-impeccable-csp-original`): append `http://localhost:PORT` to `script-src` and `connect-src` (add directive as `; <dir> 'self' <origin>` if absent), and `blob:` to `img-src`; store the original raw attribute text base64 in `data-impeccable-csp-original="…"`. The content value is patched in place on its raw text: directive names, `;` separators and existing sources are read on the decoded value the way a browser reads it (numeric references with or without `;`, and the named references that decode to ASCII; any other `&name;` is one opaque unit), the existing text and its references are copied through byte for byte, and only the inserted text is encoded for the attribute's own quote style (`&`, `<`, `>`, and the delimiting quote as `"` or `'`), so the inserted `'self'` and `'wasm-unsafe-eval'` cannot end a single-quoted attribute. A source is appended after the directive's last source; a value that ends in an unterminated reference gets a space before the added `;`. Revert writes the stored raw text back in the same quote style and removes the marker attr and the one space before it literally, so patch then revert is byte-identical (the JS built a regex from the base64 and left the marker behind when it held `+`).+CSP meta patch: for `<meta http-equiv="Content-Security-Policy" content="…">` (not already carrying `data-impeccable-csp-original`): append `http://localhost:PORT` to `script-src` and `connect-src` (add directive as `; <dir> 'self' <origin>` if absent), and `blob:` to `img-src`; store the original raw attribute text base64 in `data-impeccable-csp-original="…"`. The content value is patched in place on its raw text: directive names, `;` separators and existing sources are read on the decoded value the way a browser reads it (numeric references with or without `;`, and named references by the full HTML table: a name that decodes to ASCII is read as that character, any other real name is one opaque unit, and an `&name;` the table lacks is plain text whose `;` still separates; a legacy name without `;` decodes unless an alphanumeric or `=` follows it), the existing text and its references are copied through byte for byte, and only the inserted text is encoded for the attribute's own quote style (`&`, `<`, `>`, and the delimiting quote as `"` or `'`), so the inserted `'self'` and `'wasm-unsafe-eval'` cannot end a single-quoted attribute. A source is appended after the directive's last source; a value whose trailing text would take the added `;` as a reference terminator (`c`, `&`) gets a space before it. Revert writes the stored raw text back in the same quote style and removes the marker attr and the one space before it literally, so patch then revert is byte-identical (the JS built a regex from the base64 and left the marker behind when it held `+`).**Adapters** (kind `adapter`): SvelteKit, Nuxt, TanStack Start; the config `files` entry is NOT patched.- SvelteKit `apply({cwd,port,token,config})`: writes `src/lib/impeccable/ImpeccableLiveRoot.svelte` (script: onMount creates `<impeccable-live-root id="impeccable-live-root">` host with `all:initial;display:block;position:fixed;top:0;left:0;width:0;height:0;overflow:visible;z-index:2147483000;pointer-events:none` !important, open shadow root + reset style, sets `window.__IMPECCABLE_LIVE_ADAPTER__='sveltekit'`, `__IMPECCABLE_LIVE_UI_ROOT__`, `__IMPECCABLE_LIVE_CHROME_MOUNT__={adapter,version:1,host,root}`, appends `<script async src=LIVE_URL data-impeccable-live-script="true">`, cleanup on destroy). Patches layout (created with default `<script>\n let { children } = $props();\n</script>\n\n{@render children?.()}\n` if missing): import line `import ImpeccableLiveRoot from '$lib/impeccable/ImpeccableLiveRoot.svelte?impeccable-live=<sha256(token)[:8]>';` inserted after the first `<script…>` (or a new script block prepended), replacing an older-revision import in place; block `<!-- impeccable-live-svelte-start -->\n<ImpeccableLiveRoot />\n<!-- impeccable-live-svelte-end -->\n` inserted before `{@render children()}`/`<slot />` else appended. Result `{file: layoutRel, adapter:'sveltekit', inserted, appHtmlUntouched:true, rootComponent}`. Remove: unpatch layout (block, import, empty `<script></script>`, collapse 3+ newlines), delete component, prune empty dirs up to `src`. Journal artifacts: created `src/lib/impeccable/ImpeccableLiveRoot.svelte` marker `impeccable-live-root` pruneTo `src`; patched layout `patch:'sveltekit-layout'` markers `[SVELTE_LAYOUT_MARKER_OPEN]`.diff --git a/tests/live-e2e/agent.mjs b/tests/live-e2e/agent.mjsindex 188c936b4..5fbd807a1 100644--- a/tests/live-e2e/agent.mjs+++ b/tests/live-e2e/agent.mjs@@ -856,7 +856,18 @@ async function writeWatchedSourceFile(fullPath, body, { moduleUrl = null } = {})}const previous = await fs.readFile(fullPath, 'utf-8').catch(() => null);const servedBefore = moduleUrl && previous !== body ? await fetchServedModule(moduleUrl) : null;- await fs.writeFile(fullPath, body, 'utf-8');+ // Publish atomically: a direct write briefly exposes a truncated file that+ // the dev server can read mid-Apply and answer with a full reload. The temp+ // file sits beside the target so the rename stays on one filesystem, and+ // its `.tmp` extension is no source module any framework resolves.+ const temporaryPath = `${fullPath}.impeccable-manual-apply-${process.pid}.tmp`;+ try {+ await fs.writeFile(temporaryPath, body, 'utf-8');+ await fs.rename(temporaryPath, fullPath);+ } catch (err) {+ await fs.rm(temporaryPath, { force: true }).catch(() => {});+ throw err;+ }if (servedBefore !== null) {const deadline = Date.now() + DEV_MODULE_OBSERVE_TIMEOUT_MS;while (Date.now() < deadline) {diff --git a/tests/oracle/DELTAS.md b/tests/oracle/DELTAS.mdindex 50bb928fa..f1f8d91c6 100644--- a/tests/oracle/DELTAS.md+++ b/tests/oracle/DELTAS.md@@ -7216,3 +7216,7 @@ ordinary goldens again, not accepted deltas. The new cases`live-inject-csp-meta-quote-styles` and `live-inject-csp-meta-quote-styles-remove`pin the in-place patch of the raw content value (references kept, insertedsources encoded for the quote style) and the round trip.++## Recorded 2026-10-23: unknown named references in a CSP meta are text++The CSP meta patch read any `&name;` outside its 29 ASCII names as one opaque unit, so in `img-src https://a.example/?a&b; script-src 'self'` the `;` after `&b` was hidden: `blob:` was appended to the policy's last directive and a second `script-src` was added. A browser reads `&b;` as text, because `b` is no HTML named reference, and that `;` ends `img-src`. The patch now decides from the full HTML named-reference table (markup5ever's `NAMED_ENTITIES`, the same table as html5ever): a name that decodes to ASCII is that character, any other real name is one opaque unit, an unknown name is plain text, and a legacy name without `;` decodes unless an alphanumeric or `=` follows. New cases `live-inject-csp-meta-unknown-reference` and `live-inject-csp-meta-unknown-reference-remove`, recorded from a release build of the binary and reviewed by hand: `blob:` joins `img-src`, the existing `script-src` gains the origin and `'wasm-unsafe-eval'`, `connect-src` is added once, and remove restores the file byte for byte. No existing golden moved.diff --git a/tests/oracle/cases/live-roots.mjs b/tests/oracle/cases/live-roots.mjsindex 6ea0f6717..68d5ce3a9 100644--- a/tests/oracle/cases/live-roots.mjs+++ b/tests/oracle/cases/live-roots.mjs@@ -14,6 +14,7 @@ const PORT_NORM = [['Stopped live server on port \\d+\\.', 'g', 'Stopped live server on port <PORT>.'],];+const CSP_UNKNOWN_REFERENCE_HTML = '<!DOCTYPE html>\n<html>\n<head>\n<meta http-equiv="Content-Security-Policy" content="img-src https://a.example/?a&b; script-src \'self\'" />\n</head>\n<body>\n<h1>Hi</h1>\n</body>\n</html>\n';const CSP_QUOTE_STYLES_HTML = '<!DOCTYPE html>\n<html>\n<head>\n<meta http-equiv="Content-Security-Policy" content=\'script-src 'self' https://a.example; object-src 'none'\' />\n<meta http-equiv="Content-Security-Policy" content="script-src https://example.com/a~" />\n</head>\n<body>\n<h1>Hi</h1>\n</body>\n</html>\n';export default [@@ -98,6 +99,9 @@ export default [// Issue #1125: a single-quoted content attribute with entity-encoded quotes, and a policy whose base64 marker holds `+`. The first case pins the patched file; the second pins that remove restores it byte for byte.{ id: 'live-inject-csp-meta-quote-styles', verb: 'live-inject', workspace: 'live-html', files: [...F, 'index.html'], setup: (ws) => write(ws, 'index.html', CSP_QUOTE_STYLES_HTML), args: ['--port', '8412', '--token', 't'] },{ id: 'live-inject-csp-meta-quote-styles-remove', verb: 'live-inject', workspace: 'live-html', files: [...F, 'index.html'], setup: (ws) => write(ws, 'index.html', CSP_QUOTE_STYLES_HTML), steps: [{ args: ['--port', '8412', '--token', 't'] }, { args: ['--remove'] }] },+ // `&b;` is not an HTML named reference, so its `;` ends img-src: blob: joins img-src and the existing script-src gains the origin, with no second script-src. The second case pins the byte-identical remove.+ { id: 'live-inject-csp-meta-unknown-reference', verb: 'live-inject', workspace: 'live-html', files: [...F, 'index.html'], setup: (ws) => write(ws, 'index.html', CSP_UNKNOWN_REFERENCE_HTML), args: ['--port', '8412', '--token', 't'] },+ { id: 'live-inject-csp-meta-unknown-reference-remove', verb: 'live-inject', workspace: 'live-html', files: [...F, 'index.html'], setup: (ws) => write(ws, 'index.html', CSP_UNKNOWN_REFERENCE_HTML), steps: [{ args: ['--port', '8412', '--token', 't'] }, { args: ['--remove'] }] },{ id: 'live-inject-next-jsx', verb: 'live-inject', workspace: 'live-next', files: [...F, 'app/**'], steps: [{ args: ['--port', '8412', '--token', 't'] }, { args: ['--remove'] }] },{ id: 'live-inject-astro-inline', verb: 'live-inject', workspace: 'live-astro', files: [...F, 'src/**'], steps: [{ args: ['--port', '8412', '--token', 't'] }, { args: ['--remove'] }] },{ id: 'live-inject-sveltekit-adapter', verb: 'live-inject', workspace: 'live-sveltekit', files: [...F, 'src/**'], steps: [{ args: ['--port', '8412', '--token', 't'] }, { args: ['--port', '8412', '--token', 't'] }, { args: ['--remove'] }, { args: ['--remove'] }] },diff --git a/tests/oracle/golden/live-inject-csp-meta-unknown-reference-remove.json b/tests/oracle/golden/live-inject-csp-meta-unknown-reference-remove.jsonnew file mode 100644index 000000000..8f3627077--- /dev/null+++ b/tests/oracle/golden/live-inject-csp-meta-unknown-reference-remove.json@@ -0,0 +1,21 @@+{+ "steps": [+ {+ "stdout": "{\"ok\":true,\"port\":8412,\"gitIgnore\":{\"file\":\".gitignore\",\"mode\":\"gitignore\",\"changed\":true,\"patterns\":[\".impeccable/hook.cache.json\",\".impeccable/hook.pending.json\",\".impeccable/config.local.json\",\".impeccable/live/server.json\",\".impeccable/live/roots.json\",\".impeccable/live/app-root.json\",\".impeccable/live/inject-journal.json\",\".impeccable/live/sessions/\",\".impeccable/live/previews/\",\".impeccable/live/annotations/\",\".impeccable/live/artifacts/\",\".impeccable/live/accept-receipts/\",\".impeccable/live/locks/\",\".impeccable/live/cache/\",\".impeccable/live/manual-edit-apply-transaction.json\",\".impeccable/live/manual-edit-events.jsonl\",\".impeccable/live/manual-edit-evidence/\",\".impeccable/live/pending-manual-edits.json\",\".impeccable/live/deferred-svelte-component-accepts.json\",\".impeccable-live.json\",\".impeccable-live/\",\"app/.impeccable-live/\",\"src/.impeccable-live/\",\"node_modules/.impeccable-live/\",\"src/lib/impeccable/ImpeccableLiveRoot.svelte\",\"src/lib/impeccable/__runtime.js\",\"src/lib/impeccable/[0-9a-f]*/\",\"plugins/impeccable-live.client.ts\",\"app/plugins/impeccable-live.client.ts\",\"src/plugins/impeccable-live.client.ts\"]},\"results\":[{\"file\":\"index.html\",\"inserted\":true,\"cspPatched\":true},{\"file\":\"public/no-body.html\",\"error\":\"insertion_point_not_found\",\"anchor\":\"</body>\"},{\"file\":\"public/docs/guide.html\",\"inserted\":true,\"cspPatched\":false}]}\n",+ "stderr": "",+ "exit": 0,+ "signal": null+ },+ {+ "stdout": "{\"ok\":true,\"results\":[{\"file\":\"index.html\",\"removed\":true,\"cspReverted\":true},{\"file\":\"public/no-body.html\",\"removed\":false,\"note\":\"no tag present\"},{\"file\":\"public/docs/guide.html\",\"removed\":true,\"cspReverted\":false}]}\n",+ "stderr": "",+ "exit": 0,+ "signal": null+ }+ ],+ "files": {+ ".gitignore": "# impeccable-live-ignore-start\n.impeccable/hook.cache.json\n.impeccable/hook.pending.json\n.impeccable/config.local.json\n.impeccable/live/server.json\n.impeccable/live/roots.json\n.impeccable/live/app-root.json\n.impeccable/live/inject-journal.json\n.impeccable/live/sessions/\n.impeccable/live/previews/\n.impeccable/live/annotations/\n.impeccable/live/artifacts/\n.impeccable/live/accept-receipts/\n.impeccable/live/locks/\n.impeccable/live/cache/\n.impeccable/live/manual-edit-apply-transaction.json\n.impeccable/live/manual-edit-events.jsonl\n.impeccable/live/manual-edit-evidence/\n.impeccable/live/pending-manual-edits.json\n.impeccable/live/deferred-svelte-component-accepts.json\n.impeccable-live.json\n.impeccable-live/\napp/.impeccable-live/\nsrc/.impeccable-live/\nnode_modules/.impeccable-live/\nsrc/lib/impeccable/ImpeccableLiveRoot.svelte\nsrc/lib/impeccable/__runtime.js\nsrc/lib/impeccable/[0-9a-f]*/\nplugins/impeccable-live.client.ts\napp/plugins/impeccable-live.client.ts\nsrc/plugins/impeccable-live.client.ts\n# impeccable-live-ignore-end\n",+ ".impeccable/live/config.json": "{\n \"files\": [\"index.html\", \"public/**/*.html\"],\n \"insertBefore\": \"</body>\",\n \"commentSyntax\": \"html\"\n}\n",+ "index.html": "<!DOCTYPE html>\n<html>\n<head>\n<meta http-equiv=\"Content-Security-Policy\" content=\"img-src https://a.example/?a&b; script-src 'self'\" />\n</head>\n<body>\n<h1>Hi</h1>\n</body>\n</html>\n"+ }+}diff --git a/tests/oracle/golden/live-inject-csp-meta-unknown-reference.json b/tests/oracle/golden/live-inject-csp-meta-unknown-reference.jsonnew file mode 100644index 000000000..97116197f--- /dev/null+++ b/tests/oracle/golden/live-inject-csp-meta-unknown-reference.json@@ -0,0 +1,12 @@+{+ "stdout": "{\"ok\":true,\"port\":8412,\"gitIgnore\":{\"file\":\".gitignore\",\"mode\":\"gitignore\",\"changed\":true,\"patterns\":[\".impeccable/hook.cache.json\",\".impeccable/hook.pending.json\",\".impeccable/config.local.json\",\".impeccable/live/server.json\",\".impeccable/live/roots.json\",\".impeccable/live/app-root.json\",\".impeccable/live/inject-journal.json\",\".impeccable/live/sessions/\",\".impeccable/live/previews/\",\".impeccable/live/annotations/\",\".impeccable/live/artifacts/\",\".impeccable/live/accept-receipts/\",\".impeccable/live/locks/\",\".impeccable/live/cache/\",\".impeccable/live/manual-edit-apply-transaction.json\",\".impeccable/live/manual-edit-events.jsonl\",\".impeccable/live/manual-edit-evidence/\",\".impeccable/live/pending-manual-edits.json\",\".impeccable/live/deferred-svelte-component-accepts.json\",\".impeccable-live.json\",\".impeccable-live/\",\"app/.impeccable-live/\",\"src/.impeccable-live/\",\"node_modules/.impeccable-live/\",\"src/lib/impeccable/ImpeccableLiveRoot.svelte\",\"src/lib/impeccable/__runtime.js\",\"src/lib/impeccable/[0-9a-f]*/\",\"plugins/impeccable-live.client.ts\",\"app/plugins/impeccable-live.client.ts\",\"src/plugins/impeccable-live.client.ts\"]},\"results\":[{\"file\":\"index.html\",\"inserted\":true,\"cspPatched\":true},{\"file\":\"public/no-body.html\",\"error\":\"insertion_point_not_found\",\"anchor\":\"</body>\"},{\"file\":\"public/docs/guide.html\",\"inserted\":true,\"cspPatched\":false}]}\n",+ "stderr": "",+ "exit": 0,+ "signal": null,+ "files": {+ ".gitignore": "# impeccable-live-ignore-start\n.impeccable/hook.cache.json\n.impeccable/hook.pending.json\n.impeccable/config.local.json\n.impeccable/live/server.json\n.impeccable/live/roots.json\n.impeccable/live/app-root.json\n.impeccable/live/inject-journal.json\n.impeccable/live/sessions/\n.impeccable/live/previews/\n.impeccable/live/annotations/\n.impeccable/live/artifacts/\n.impeccable/live/accept-receipts/\n.impeccable/live/locks/\n.impeccable/live/cache/\n.impeccable/live/manual-edit-apply-transaction.json\n.impeccable/live/manual-edit-events.jsonl\n.impeccable/live/manual-edit-evidence/\n.impeccable/live/pending-manual-edits.json\n.impeccable/live/deferred-svelte-component-accepts.json\n.impeccable-live.json\n.impeccable-live/\napp/.impeccable-live/\nsrc/.impeccable-live/\nnode_modules/.impeccable-live/\nsrc/lib/impeccable/ImpeccableLiveRoot.svelte\nsrc/lib/impeccable/__runtime.js\nsrc/lib/impeccable/[0-9a-f]*/\nplugins/impeccable-live.client.ts\napp/plugins/impeccable-live.client.ts\nsrc/plugins/impeccable-live.client.ts\n# impeccable-live-ignore-end\n",+ ".impeccable/live/config.json": "{\n \"files\": [\"index.html\", \"public/**/*.html\"],\n \"insertBefore\": \"</body>\",\n \"commentSyntax\": \"html\"\n}\n",+ ".impeccable/live/inject-journal.json": "{\n \"version\": 1,\n \"appRoot\": \"<WS>\",\n \"framework\": \"static-html\",\n \"port\": 8412,\n \"pid\": <PID>,\n \"recordedAt\": \"<ISO>\",\n \"artifacts\": [\n {\n \"kind\": \"patched\",\n \"path\": \"index.html\",\n \"patch\": \"live-tag\",\n \"markers\": [\n \"impeccable-live-start\",\n \"data-impeccable-csp-original\"\n ]\n },\n {\n \"kind\": \"patched\",\n \"path\": \"public/docs/guide.html\",\n \"patch\": \"live-tag\",\n \"markers\": [\n \"impeccable-live-start\",\n \"data-impeccable-csp-original\"\n ]\n }\n ]\n}\n",+ "index.html": "<!DOCTYPE html>\n<html>\n<head>\n<meta http-equiv=\"Content-Security-Policy\" content=\"img-src https://a.example/?a&b blob:; script-src 'self' http://localhost:8412 'wasm-unsafe-eval'; connect-src 'self' http://localhost:8412\" data-impeccable-csp-original=\"aW1nLXNyYyBodHRwczovL2EuZXhhbXBsZS8/YSZiOyBzY3JpcHQtc3JjICdzZWxmJw==\" />\n</head>\n<body>\n<h1>Hi</h1>\n<!-- impeccable-live-start -->\n<script src=\"http://localhost:8412/live.js?token=t\"></script>\n<!-- impeccable-live-end -->\n</body>\n</html>\n"+ }+}