The best way to control Claude Code, Codex and more from any computer or phone
fix(shared): theme CSS checks allow url() inside a quoted data: address (#36696)
Julius Marminge committed
Nov 14, 2026 at 04:01 UTC
c3517ec0bfe40f8be3cf9a453bb523dbcac4030a
2 files changed
+30
-3
packages/shared/src/themeCss.test.ts
+16
-1
@@ -1,6 +1,10 @@
1
import { describe, expect, it } from "vite-plus/test";
2
3
-import { themeCssValueFetches } from "./themeCss.ts";
3
+import { themeCssLoadsRemoteFiles, themeCssValueFetches } from "./themeCss.ts";
4
+
5
+// %23 decodes to # inside the SVG, so url(%23g) names its own gradient.
6
+const SVG_WITH_OWN_GRADIENT =
7
+ "data:image/svg+xml,%3Csvg xmlns=%22http://www.w3.org/2000/svg%22%3E%3ClinearGradient id=%22g%22/%3E%3Crect fill=%22url(%23g)%22/%3E%3C/svg%3E";
8
9
describe("themeCssValueFetches", () => {
10
it.each([
@@ -14,6 +18,9 @@ describe("themeCssValueFetches", () => {
18
// A no-break space before the scheme makes this a path on the app's own origin.
19
["background-image", 'url("\u00a0data:/../../probe")', true],
20
["background-image", 'url("data:image/png;base64,AA")', false],
21
+ ["background-image", `url("${SVG_WITH_OWN_GRADIENT}")`, false],
22
+ // The url( sits inside a string, so the address after that string is a real remote url().
23
+ ["content", `"url('data:" url("https://evil.example/a") "'"`, true],
24
["filter", 'url("#blur")', false],
25
["background-image", "var(--pattern)", false],
26
["color", "red", false],
@@ -21,3 +28,11 @@ describe("themeCssValueFetches", () => {
28
expect(themeCssValueFetches(value)).toBe(fetches);
29
});
30
});
31
+
32
+describe("themeCssLoadsRemoteFiles", () => {
33
+ it("allows a url() inside a data: address", () => {
34
+ expect(
35
+ themeCssLoadsRemoteFiles(`.repro { background-image: url('${SVG_WITH_OWN_GRADIENT}'); }`),
36
+ ).toBe(false);
37
+ });
38
+});
packages/shared/src/themeCss.ts
+14
-2
@@ -3,6 +3,18 @@ import { THEME_COLOR_ROLES } from "./themePalettes.ts";
3
const FETCHES_BY_STRING = /image-set\(|\bsrc\(/i;
4
// Only CSS whitespace may come first. \s also matches U+00A0, which makes the address relative.
5
const URL_NOT_LOCAL = /url\((?![ \t\n\f\r]*["']?(?:data:|#))/i;
6
+// Read tokens left to right, as CSS does: a url( inside a string loads nothing, and a quote in an
7
+// unquoted url( is not a string. A quoted url() that is not data: or #id keeps `url(` for the check.
8
+const URL_OR_STRING =
9
+ /url\((?![ \t\n\f\r]*["'])[^)]*|url\([ \t\n\f\r]*("[^"\n\r\f]*"|'[^'\n\r\f]*')|"[^"\n\r\f]*"|'[^'\n\r\f]*'/gi;
10
+
11
+function fetchesByText(code: string): boolean {
12
+ const outsideStrings = code.replace(URL_OR_STRING, (token, urlString: string | undefined) => {
13
+ if (urlString !== undefined) return /^["'](?:data:|#)/i.test(urlString) ? "" : "url(";
14
+ return token.startsWith('"') || token.startsWith("'") ? "" : token;
15
+ });
16
+ return FETCHES_BY_STRING.test(outsideStrings) || URL_NOT_LOCAL.test(outsideStrings);
17
+}
18
19
/**
20
* Whether one declaration value can load a remote file. Clients drop those declarations.
@@ -10,13 +22,13 @@ const URL_NOT_LOCAL = /url\((?![ \t\n\f\r]*["']?(?:data:|#))/i;
22
* so every value that still has a backslash is refused.
23
*/
24
export function themeCssValueFetches(value: string): boolean {
13
- return value.includes("\\") || FETCHES_BY_STRING.test(value) || URL_NOT_LOCAL.test(value);
25
+ return value.includes("\\") || fetchesByText(value);
26
}
27
28
/** A text check for early feedback. CSS escapes can dodge it; the client check is the guard. */
29
export function themeCssLoadsRemoteFiles(css: string): boolean {
30
const code = css.replace(/\/\*[\s\S]*?\*\//g, "");
19
- return /@import/i.test(code) || FETCHES_BY_STRING.test(code) || URL_NOT_LOCAL.test(code);
31
+ return /@import/i.test(code) || fetchesByText(code);
32
}
33
34
/**