Skip to content

fix(web): theme CSS shorthands with var() can no longer load remote files - #39408

Open
juliusmarminge wants to merge 2 commits into
mainfrom
factory/pr-39346-a1795125289
Open

juliusmarminge wants to merge 2 commits into
mainfrom
factory/pr-39346-a1795125289

Conversation

@juliusmarminge

@juliusmarminge juliusmarminge commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

Theme CSS must not load remote files, but a shorthand containing var() slipped past the client guard: for background: var(--none, url(https://example.com/h)) every longhand reads as empty until substitution, so the per-property check saw nothing and the browser requested the URL. Such shorthands are now removed, including when a later declaration in the same block overrides one of their longhands and the browser hides the shorthand's text.

  • packages/shared/src/themeCss.ts: themeCssWithoutDeclarations splits the theme source into declarations and drops the ones the caller refuses, asking only about text that could fetch.
  • apps/web/src/themeCss.ts: before building the theme sheet, withoutFetchingShorthands lets the browser parse each such declaration alone and cuts it from the source when it is a var() shorthand that can fetch, so CSS escapes cannot dodge the check.
  • stripDeclarations also removes the pending longhands of a block whose own cssText still shows a fetching shorthand.
  • Harmless shorthands stay: the documented background: var(--theme-background-image) center / cover no-repeat; is kept, and so is a var() shorthand with an overridden longhand, whatever other rules in the theme hold.

Supersedes #39346. The change is @elias1218's; their commits are kept.

Reproduction on main

Reproduced on main at 66b8a94:

  1. Paired the browser and opened Settings > Appearance. Built-in themes have no Export button, so I built the theme file with the same function Export uses (serializeThemeFile, dark default colors), then set a new id and name and the css field. 2) Add theme > chose the JSON file > Add theme. The toast said 'Probe ... added. It's now your dark theme.' and the theme was selected. No example.com request while on the settings page. 3) Added a local folder (a fresh git repo) as a project through Add project > Local folder and opened its new-thread draft, which has [data-workspace-area="conversation"]. Override case, css [data-workspace-area="conversation"] { background: var(--screen-missing, url(https://example.com/theme-shorthand-probe-override2)); background-color: red; }: Chromium sent GET https://example.com/theme-shorthand-probe-override2. The filtered adopted sheet still held the rule with empty values for every background longhand (background-image: ; ... background-color: red;). Computed background-image was url("https://example.com/theme-shorthand-probe-override2") and background-color was rgb(255, 0, 0). Intact case, the same rule without background-color: the adopted sheet kept the shorthand as written, Chromium sent GET https://example.com/theme-shorthand-probe-intact, and the computed background-image was that URL. On main, theme CSS applied by the web client loads remote resources through var() shorthands in both of the forms the pull request names. Not checked here: the server-side escaped-function-name text check.

Evidence

In Chromium, import and select each dark theme through Settings > Appearance, then open a seeded conversation. Test background: var(--screen-missing, url(...)) both with and without a later background-color: red. Browser routing records attempted remote requests and supplies the visible probe image; the labeled instrumentation reports requests and computed background-image.

Proven: scenarios:prove exited 0. Both forms request an image on base; neither requests one on head.

Case Before — 210996207d After — 3b7520bdee
Result One remote request per case; computed image is the remote URL Zero remote requests; computed image is none
Overridden shorthand Before: overridden shorthand requests remote image After: remote image blocked, red color retained
Intact shorthand Before: intact shorthand requests remote image After: intact shorthand remote image blocked

Scenario source · Before recording · After recording

Not shown:

  • Desktop was not launched; this proof exercises the web client.
  • The documented local --theme-background-image shorthand was not exercised.
  • The server-side escaped-function-name text check was not exercised.

Tests

  • vp test run --project browser src/themeCss.browser.test.ts (apps/web, two-rule case against the earlier commit d814c26): failed as expected, expected 'none' to contain 'linear-gradient'
  • vp test run --project browser src/themeCss.browser.test.ts (apps/web, at 3b7520b): 1 passed
  • vp test run src/themeCss.test.ts (packages/shared): 37 passed
  • scratch adversarial sweep in Chromium (54 hostile theme inputs and 4 harmless-beside-fetching cases, not committed): passed, no leaks, no requests, no lost styles
  • vp run check:changed: format, lint, knip, typecheck (36 packages), test (3 files) and react compiler all pass
  • CI on pull request fix(web): theme CSS shorthands with var() can no longer load remote files #39408 at 3b7520b: all 38 checks passed, including the 8 required ones

Not in this change

  • The server's text check themeCssLoadsRemoteFiles is unchanged; it stays early feedback that escapes can dodge, and the client check remains the guard.
  • Imported themes still get no server-side text check; the client guard is what covers them.
  • Firefox and WebKit were not tested; the guard relies on Chromium's serialization of pending shorthands, as the web and desktop clients run on Chromium.
  • A var() shorthand whose own value holds a CSS escape is still removed even when it cannot fetch, matching how the existing check refuses escapes in values.

Who did the work

  • Written by Claude Fable 5.2, in Claude Code
  • Reviewed by GPT-6.1 Sol, in Codex, and by Claude Opus 5.5, each on its own
  • Proof captured by GPT-6.1 Sol and checked by Claude Opus 5.5

Run by the t3code factory in T3 Code.

juliusmarminge and others added 2 commits November 19, 2026 22:28
…iles

Theme CSS must not fetch, but the client guard read each longhand's value,
and a shorthand holding var() leaves its longhands reading "" until
substitution. `background: var(--none, url(https://example.com/h))` passed
the guard and the browser requested the URL.

The guard now also judges pending longhands. While the block's cssText
shows the shorthand, that text decides. Once a later declaration overrides
one longhand the browser hides the text, so the theme's source decides:
declarations that could fetch are split out, the browser parses each one
alone, and only the longhands such a shorthand leaves pending are removed
from blocks that hide them. A harmless overridden shorthand stays, whatever
escapes or fetches the rest of the sheet holds.

Co-authored-by: elias1218 <69803556+elias1218@users.noreply.github.com>

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…theirs

The guard removed hidden pending longhands by name across the whole sheet,
so `.unused { background: var(--none, url(https://example.com/x)); }` took
the gradient from a harmless `background: var(...); background-color: red;`
in another rule.

A var() shorthand that can fetch is now cut from the theme's source before
the sheet is built, so removal is tied to that one declaration and nothing
is left for a later declaration to hide. Blocks that keep a pending
shorthand are no longer judged by what other rules hold.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@github-actions github-actions Bot added vouch:trusted Author is trusted by repo permissions or the VOUCHED list. size:L 100-499 changed lines (additions + deletions). labels Nov 19, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Thread transfer impact

✅ Thread transfer remains within every enforced ceiling.

Provider Metric Main baseline This PR Impact PR ceiling
Codex Total thread wire 5.0 KiB 5.0 KiB 0 B (0.0%) 6.8 KiB ✅
Codex Thread snapshot wire 3.8 KiB 3.8 KiB 0 B (0.0%) 4.9 KiB ✅
Codex Live turn WebSocket wire 1.2 KiB 1.2 KiB 0 B (0.0%) 2.0 KiB ✅
Codex Live turn WebSocket decoded 21.5 KiB 21.5 KiB 0 B (0.0%) 24.4 KiB ✅
Codex Live turn messages 1 1 0 (0.0%) 8 ✅
Claude Total thread wire 5.0 KiB 5.0 KiB 0 B (0.0%) 6.8 KiB ✅
Claude Thread snapshot wire 3.8 KiB 3.8 KiB 0 B (0.0%) 4.9 KiB ✅
Claude Live turn WebSocket wire 1.2 KiB 1.2 KiB 0 B (0.0%) 2.0 KiB ✅
Claude Live turn WebSocket decoded 21.9 KiB 21.9 KiB 0 B (0.0%) 24.4 KiB ✅
Claude Live turn messages 1 1 0 (0.0%) 8 ✅

Other scenarios

All 64 scenario measurements match main.

All 64 scenario measurements
Provider Scenario Metric Main baseline This PR Impact PR ceiling
Codex short turn resume WebSocket decoded 10.5 KiB 10.5 KiB 0 B (0.0%) 12.7 KiB ✅
Codex short turn resume WebSocket messages 2 2 0 (0.0%) 2 ✅
Codex long turn running, cold open HTTP decoded 281.7 KiB 281.7 KiB 0 B (0.0%) 302.7 KiB ✅
Codex long turn running, cold open rows 75 75 0 (0.0%) 75 ✅
Codex long turn running, history page HTTP decoded 92.4 KiB 92.4 KiB 0 B (0.0%) 107.4 KiB ✅
Codex long turn running, history page rows 75 75 0 (0.0%) 75 ✅
Codex long turn finished, cold open HTTP decoded 381.5 KiB 381.5 KiB 0 B (0.0%) 410.2 KiB ✅
Codex long turn finished, cold open rows 151 151 0 (0.0%) 151 ✅
Codex long turn finished, socket cold open WebSocket decoded 381.6 KiB 381.6 KiB 0 B (0.0%) 410.2 KiB ✅
Codex long turn finished, socket cold open WebSocket messages 2 2 0 (0.0%) 2 ✅
Codex long turn finished, socket cold open rows 151 151 0 (0.0%) 151 ✅
Codex long turn finished, work page HTTP decoded 186.2 KiB 186.2 KiB 0 B (0.0%) 200.2 KiB ✅
Codex long turn finished, work page rows 150 150 0 (0.0%) 150 ✅
Codex idle thread resume WebSocket decoded 65 B 65 B 0 B (0.0%) 200 B ✅
Codex idle thread resume WebSocket messages 1 1 0 (0.0%) 1 ✅
Codex fleet shell snapshot HTTP decoded 42.4 KiB 42.4 KiB 0 B (0.0%) 53.7 KiB ✅
Codex fleet shell snapshot rows 27 27 0 (0.0%) 27 ✅
Codex fleet shell subscribe WebSocket decoded 65 B 65 B 0 B (0.0%) 200 B ✅
Codex fleet shell subscribe WebSocket messages 1 1 0 (0.0%) 1 ✅
Codex fleet shell resume check HTTP decoded 18 B 18 B 0 B (0.0%) 100 B ✅
Codex fleet shell resume check rows 0 0 0 0 ✅
Codex stale shell reload HTTP decoded 42.4 KiB 42.4 KiB 0 B (0.0%) 53.7 KiB ✅
Codex stale shell reload rows 27 27 0 (0.0%) 27 ✅
Codex stale shell resume WebSocket decoded 140 B 140 B 0 B (0.0%) 400 B ✅
Codex stale shell resume WebSocket messages 2 2 0 (0.0%) 2 ✅
Codex stale todo list cold open HTTP decoded 72.4 KiB 72.4 KiB 0 B (0.0%) 83.0 KiB ✅
Codex stale todo list cold open rows 75 75 0 (0.0%) 75 ✅
Codex stale todo list cold open nodes 2 2 0 (0.0%) 4 ✅
Codex stale todo list cold open subagents 2 2 0 (0.0%) 4 ✅
Codex stale todo list cold open plans 1 1 0 (0.0%) 2 ✅
Codex stale todo list cold open providerTurns 1 1 0 (0.0%) 2 ✅
Codex stale todo list cold open checkpoints 1 1 0 (0.0%) 2 ✅
Claude short turn resume WebSocket decoded 10.6 KiB 10.6 KiB 0 B (0.0%) 12.7 KiB ✅
Claude short turn resume WebSocket messages 2 2 0 (0.0%) 2 ✅
Claude long turn running, cold open HTTP decoded 283.3 KiB 283.3 KiB 0 B (0.0%) 302.7 KiB ✅
Claude long turn running, cold open rows 75 75 0 (0.0%) 75 ✅
Claude long turn running, history page HTTP decoded 93.4 KiB 93.4 KiB 0 B (0.0%) 107.4 KiB ✅
Claude long turn running, history page rows 75 75 0 (0.0%) 75 ✅
Claude long turn finished, cold open HTTP decoded 384.2 KiB 384.2 KiB 0 B (0.0%) 410.2 KiB ✅
Claude long turn finished, cold open rows 151 151 0 (0.0%) 151 ✅
Claude long turn finished, socket cold open WebSocket decoded 384.3 KiB 384.3 KiB 0 B (0.0%) 410.2 KiB ✅
Claude long turn finished, socket cold open WebSocket messages 2 2 0 (0.0%) 2 ✅
Claude long turn finished, socket cold open rows 151 151 0 (0.0%) 151 ✅
Claude long turn finished, work page HTTP decoded 188.1 KiB 188.1 KiB 0 B (0.0%) 200.2 KiB ✅
Claude long turn finished, work page rows 150 150 0 (0.0%) 150 ✅
Claude idle thread resume WebSocket decoded 66 B 66 B 0 B (0.0%) 200 B ✅
Claude idle thread resume WebSocket messages 1 1 0 (0.0%) 1 ✅
Claude fleet shell snapshot HTTP decoded 43.0 KiB 43.0 KiB 0 B (0.0%) 53.7 KiB ✅
Claude fleet shell snapshot rows 27 27 0 (0.0%) 27 ✅
Claude fleet shell subscribe WebSocket decoded 66 B 66 B 0 B (0.0%) 200 B ✅
Claude fleet shell subscribe WebSocket messages 1 1 0 (0.0%) 1 ✅
Claude fleet shell resume check HTTP decoded 18 B 18 B 0 B (0.0%) 100 B ✅
Claude fleet shell resume check rows 0 0 0 0 ✅
Claude stale shell reload HTTP decoded 43.0 KiB 43.0 KiB 0 B (0.0%) 53.7 KiB ✅
Claude stale shell reload rows 27 27 0 (0.0%) 27 ✅
Claude stale shell resume WebSocket decoded 140 B 140 B 0 B (0.0%) 400 B ✅
Claude stale shell resume WebSocket messages 2 2 0 (0.0%) 2 ✅
Claude stale todo list cold open HTTP decoded 73.4 KiB 73.4 KiB 0 B (0.0%) 83.0 KiB ✅
Claude stale todo list cold open rows 75 75 0 (0.0%) 75 ✅
Claude stale todo list cold open nodes 2 2 0 (0.0%) 4 ✅
Claude stale todo list cold open subagents 2 2 0 (0.0%) 4 ✅
Claude stale todo list cold open plans 1 1 0 (0.0%) 2 ✅
Claude stale todo list cold open providerTurns 1 1 0 (0.0%) 2 ✅
Claude stale todo list cold open checkpoints 1 1 0 (0.0%) 2 ✅

Baseline: 57db750 · PR result: 3b7520b · Source CI: success

Scenario and decoded snapshot size

10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.

  • Codex decoded thread snapshot: 108.5 KiB
  • Claude decoded thread snapshot: 108.8 KiB

Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.

@elias1218

Copy link
Copy Markdown
Contributor

Thanks for taking this over! When this gets squash-merged, could the Co-authored-by: elias1218 line from d814c26 stay in the commit message? I'll close #39346 as superseded.

@coderabbitai

coderabbitai Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The shared CSS scanner identifies declaration candidates for removal. The web theme CSS path uses it to filter fetch-capable shorthands before replacing the theme stylesheet, with tests for remote URLs and retained safe styles.

Changes: Theme CSS filtering

Layer / File(s) Summary
Declaration scanning and tests
packages/shared/src/themeCss.ts, packages/shared/src/themeCss.test.ts
themeCssWithoutDeclarations scans CSS candidates while tracking nested syntax and removes candidates rejected by its callback. Tests cover candidate boundaries and selective removal.
Filter fetch-capable theme shorthands
apps/web/src/themeCss.ts, apps/web/src/themeCss.browser.test.ts
The web theme CSS path detects fetch-capable pending shorthands and filters the CSS before stylesheet replacement. Browser tests check removal of remote URLs and retention of safe styles.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Bug fix

Possibly related PRs

  • pingdotgg/t3code#35247: Adds custom theme CSS and a client filter for CSS that could load remote files.
  • pingdotgg/t3code#39346: Addresses theme CSS var() shorthands that can hide url() fetches from per-property checks.

Suggested labels: bugfix

Suggested reviewers: t3dotgg, macroscopeapp

Merge Risk: Minimal · up to 3b752

This change stops theme CSS shorthands that use var() from loading remote files, while keeping harmless theme styles. No concrete defect was found in the changed code. The guard relies on Chromium behavior, and other browsers were not tested, which is worth knowing but does not block merging.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: theme CSS shorthands that use var() can no longer load remote files. The changeset adds client-side removal of fetch-capable var() shorthands in applyThemeCss and a sh…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description check Passed The description follows the repository template closely. It has all five sections: Problem, Change, Scope, Verification, and the agent attribution line. The Problem section explains the bypass: a shor…
Full details: Title check

Explanation

The title names the main change: theme CSS shorthands that use var() can no longer load remote files. The changeset adds client-side removal of fetch-capable var() shorthands in applyThemeCss and a shared themeCssWithoutDeclarations helper, so the title matches the primary fix. It is in conventional commit form and specific enough for a reviewer scanning history.

Full details: Description check

Explanation

The description follows the repository template closely. It has all five sections: Problem, Change, Scope, Verification, and the agent attribution line. The Problem section explains the bypass: a shorthand containing var() evades the per-longhand guard, so the browser requests a remote URL. The Change section lists the changed files and the new helpers. The Scope section says the PR supersedes #39346 and carries the original author's commits, but it does not link a tracked issue for the bug or say why no issue is needed. The Verification section is strong. It gives a before/after reproduction on main, screenshots, a proof run, and the tests executed. It also states what was not checked: Firefox, WebKit, desktop, and the server-side escape check. The attribution line names the models and harness. The only gap is the missing issue link or justification in Scope, which is a non-critical item for a template-driven PR. The description is mostly complete, so the check passes.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 57db750 and 3b7520b.

Files selected for processing: 4

  • apps/web/src/themeCss.browser.test.ts
  • apps/web/src/themeCss.ts
  • packages/shared/src/themeCss.test.ts
  • packages/shared/src/themeCss.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L 100-499 changed lines (additions + deletions). vouch:trusted Author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants