Files
webspeak3/gateway/test/store-css.test.mjs
T
MoepchiandClaude Opus 5.5 deff678cfa Store: CSS filter bypasses via comments in strings and vendor prefixes
normalizeCss stripped /* */ without knowing about strings or escapes, so
content:"/*" ... "*/" hid a url() between them from the checks, and
-webkit-image-set( slipped past the function-name boundary. The checks
now run with and without comment stripping and allow a vendor prefix.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Hu2cuPLqpuKVfd9wWFFakU
2026-11-25 12:50:25 +00:00

22 lines
947 B
JavaScript

// Theme CSS from the Design Store must never load anything external.
import { test } from "node:test";
import assert from "node:assert/strict";
import { isSafeThemeCss } from "../dist/store.js";
test("theme CSS filter", () => {
const evil = "url(https://attacker.example/t.png)";
for (const css of [
`body{background:${evil}}`,
`body{background:\\75rl(https://attacker.example/t.png)}`,
`body{background:image-set("https://attacker.example/t.png" 1x)}`,
`a{content:"/*"}body{background:${evil}}b{content:"*/"}`,
`a{--x:\\/*}body{background:${evil}}b{--y:*/}`,
`body{background:-webkit-image-set("https://attacker.example/t.png" 1x)}`,
]) assert.equal(isSafeThemeCss(css), false, css);
for (const css of [
":root{--bg:#123}body{color:red}a:hover{opacity:.5}",
"body{background:url(data:image/png;base64,AAAA)}",
"/* a comment */ body{color:red}",
]) assert.equal(isSafeThemeCss(css), true, css);
});