is live markup Chromium honors.
// The original neutralizer only rewrote quoted values.
test("neutralizes remote url() in UNQUOTED style attributes", () => {
const out = sanitizeUntrustedHtml(`
x
`);
expect(out).not.toContain("evil.example");
expect(out).toContain("url(#)");
});
test("keeps local url() in unquoted style attributes functional", () => {
const out = sanitizeUntrustedHtml(`
x
`);
expect(out).toContain("url(local.png)");
});
// ── Bypass regressions: CSS-escape obfuscation ──
// Chromium decodes CSS ident/string escapes before fetching, so \69 → i and
// \68 → h defeat literal-pattern matching. Untrusted styling has no
// legitimate need for escaped url schemes or at-rule names — fail closed.
test("drops CSS-escaped @import (@\\69mport url(...)) in `);
expect(out).not.toContain("evil.example");
expect(out).not.toMatch(/@\\/); // no escaped at-rule survives for Chromium to decode
});
test("drops CSS-escaped string-form @import (@\\69mport \"https://…\")", () => {
const out = sanitizeUntrustedHtml(``);
expect(out).not.toContain("evil.example");
expect(out).not.toMatch(/@\\/);
});
test("neutralizes CSS-escaped scheme inside url() (\\68ttps://…)", () => {
const out = sanitizeUntrustedHtml(``);
expect(out).not.toContain("evil.example");
});
test("neutralizes CSS-escaped function names (u\\72l(https://…))", () => {
const out = sanitizeUntrustedHtml(``);
expect(out).not.toContain("evil.example");
});
test("neutralizes HTML-entity-encoded backslash escapes in style attributes", () => {
// Attribute values are entity-decoded by the HTML parser before the CSS
// parser runs, so \68ttps reaches Chromium as \68ttps → https.
const out = sanitizeUntrustedHtml(`
x
`);
expect(out).not.toContain("evil.example");
});
// ── Bypass regressions: non-backslash entity obfuscation in style attrs ──
// The same attribute entity layer can hide ANY character of a fetch vector,
// not just backslashes: h → h, / → /. `,
`
hi
`,
`

`,
].join("\n\n");
const { bodyHtml } = render({ markdown: md });
expect(bodyHtml).not.toContain("evil.example");
});
test("end-to-end: unquoted and CSS-escaped vectors don't survive render()", () => {
const md = [
"# Doc",
``,
`
hi
`,
].join("\n\n");
const { bodyHtml } = render({ markdown: md });
expect(bodyHtml).not.toContain("evil.example");
expect(bodyHtml).not.toMatch(/@\\/);
});
});