[PR #2586] [MERGED] fix(chat): harden card CSS sanitizer against escape-sequence evasion #5671

Closed
opened 2026-10-22 04:18:22 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/2586
Author: @kolacheee
Created: 6/16/2026
Status: ✅ Merged
Merged: 6/16/2026
Merged by: @SpicyMarinara

Base: staging ← Head: feat/staging-cardcss-sanitizer-hardening


📝 Commits (2)

  • e6fe37a fix(chat): harden card CSS sanitizer against escape-sequence evasion
  • 3e8c3d9 Merge branch 'staging' into feat/staging-cardcss-sanitizer-hardening

📊 Changes

1 file changed (+30 additions, -1 deletions)

View changed files

📝 packages/client/src/components/chat/ChatMessage.tsx (+30 -1)

📄 Description

Draft. Security hardening; tsc + ESLint pass and the bypass/benign cases are unit-verified (see notes). Independent of the gallery PRs — branches off staging.

Linked issue

Closes #2577

Why this change

  • staging renders creator card CSS through an inline <style> sanitizer in ChatMessage.tsx that is a regex blocklist over raw text. The CSS engine decodes escape sequences (\XX hex, \c), so a guard matching literal keyword text can be bypassed by spelling the token with escapes — e.g. \75rl(//evil) evades the url() guard, po\73ition / expre\73sion( / @\69mport / beha\76ior: all slip past. This is the same gap #2020 fixed on refactor; porting it closes it on staging.

What changed

  • Add canonicalizeKeywordEscapes() (with decodeCssEscapes() + a STRING_OR_ESCAPE scanner) and run it at the top of sanitizeChatCss, before the existing guards.
  • It decodes escapes that resolve to ASCII letters, @, or -, so the literal-text guards see the tokens the browser would actually parse.
  • It preserves escapes resolving to digits/punctuation and all escape sequences inside string literals, so benign selectors like .\32 xl and .w-1\/2 and legit content: "…" strings stay byte-exact.
  • No behavior change for well-formed CSS; confined to the sanitizer.

Validation

  • pnpm check passes locally
  • Container (Docker / Podman) built and ran without issue
  • Ran the app, clicked through the changes manually
  • Checked edge cases (light + dark mode, mobile viewport, empty states, error paths)
  • Above manual verification completed (describe below)
  • Read and followed CONTRIBUTING.md

Manual verification notes

Automated: tsc -b + ESLint pass for the client. Ran the exact ported sanitizer logic against a bypass/benign matrix — 7/7: escaped expression(), javascript:, @import, behavior:, and a non-https escaped url() are all neutralized; a digit-escape selector (.\32 xl) and an escape inside a string literal are preserved unchanged.

To verify manually in-browser (TO-DO): put card CSS like .x{ ba\63kground: \75rl(//example.test/p.png) } in a character's creator notes and confirm no external request is made / the rule is neutralized, and that a normal Tailwind-ish selector with an escaped digit still renders.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed
  • Version/release files updated (only if this PR includes a version bump)

Assessment (please confirm): internal hardening — no docs/version changes expected.

UI evidence (if applicable)

N/A — no visual change for well-formed CSS.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/2586 **Author:** [@kolacheee](https://github.com/kolacheee) **Created:** 6/16/2026 **Status:** ✅ Merged **Merged:** 6/16/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `feat/staging-cardcss-sanitizer-hardening` --- ### 📝 Commits (2) - [`e6fe37a`](https://github.com/Pasta-Devs/Marinara-Engine/commit/e6fe37a266b5e65ce1bcc835dda22183bb011b68) fix(chat): harden card CSS sanitizer against escape-sequence evasion - [`3e8c3d9`](https://github.com/Pasta-Devs/Marinara-Engine/commit/3e8c3d9ffe5253875a27116cce27f2bb3fe86c2c) Merge branch 'staging' into feat/staging-cardcss-sanitizer-hardening ### 📊 Changes **1 file changed** (+30 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `packages/client/src/components/chat/ChatMessage.tsx` (+30 -1) </details> ### 📄 Description > **Draft.** Security hardening; `tsc` + ESLint pass and the bypass/benign cases are unit-verified (see notes). Independent of the gallery PRs — branches off `staging`. ## Linked issue Closes #2577 ## Why this change - `staging` renders creator card CSS through an inline `<style>` sanitizer in `ChatMessage.tsx` that is a **regex blocklist over raw text**. The CSS engine decodes escape sequences (`\XX` hex, `\c`), so a guard matching literal keyword text can be bypassed by spelling the token with escapes — e.g. `\75rl(//evil)` evades the `url()` guard, `po\73ition` / `expre\73sion(` / `@\69mport` / `beha\76ior:` all slip past. This is the same gap #2020 fixed on `refactor`; porting it closes it on `staging`. ## What changed - Add `canonicalizeKeywordEscapes()` (with `decodeCssEscapes()` + a `STRING_OR_ESCAPE` scanner) and run it at the **top** of `sanitizeChatCss`, before the existing guards. - It decodes escapes that resolve to ASCII letters, `@`, or `-`, so the literal-text guards see the tokens the browser would actually parse. - It **preserves** escapes resolving to digits/punctuation and all escape sequences inside string literals, so benign selectors like `.\32 xl` and `.w-1\/2` and legit `content: "…"` strings stay byte-exact. - No behavior change for well-formed CSS; confined to the sanitizer. ## Validation - [ ] `pnpm check` passes locally - [ ] Container (Docker / Podman) built and ran without issue - [ ] Ran the app, clicked through the changes manually - [ ] Checked edge cases (light + dark mode, mobile viewport, empty states, error paths) - [ ] Above manual verification completed (describe below) - [ ] Read and followed `CONTRIBUTING.md` ### Manual verification notes Automated: `tsc -b` + ESLint pass for the client. Ran the exact ported sanitizer logic against a bypass/benign matrix — **7/7**: escaped `expression()`, `javascript:`, `@import`, `behavior:`, and a non-https escaped `url()` are all neutralized; a digit-escape selector (`.\32 xl`) and an escape inside a string literal are preserved unchanged. To verify manually in-browser (TO-DO): put card CSS like `.x{ ba\63kground: \75rl(//example.test/p.png) }` in a character's creator notes and confirm no external request is made / the rule is neutralized, and that a normal Tailwind-ish selector with an escaped digit still renders. ## Docs and release impact - [ ] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed - [ ] Version/release files updated (only if this PR includes a version bump) Assessment (please confirm): internal hardening — no docs/version changes expected. ## UI evidence (if applicable) N/A — no visual change for well-formed CSS. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-22 04:18:22 +07:00
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#5671
No description provided.