mirror of
https://github.com/Moepchi/webspeak3.git
synced 2026-12-01 00:42:49 +08:00
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
22 lines
947 B
JavaScript
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);
|
|
});
|