[PR #2020] [MERGED] Harden card CSS sanitizer against escape-sequence evasion #5392

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

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/2020
Author: @kolacheee
Created: 6/3/2026
Status: ✅ Merged
Merged: 6/4/2026
Merged by: @cha1latte

Base: refactor ← Head: fix/card-css-escape-sanitizer


📝 Commits (1)

  • 7569011 Harden card CSS sanitizer against escape evasion

📊 Changes

1 file changed (+48 additions, -0 deletions)

View changed files

📝 src/shared/lib/chat-css.ts (+48 -0)

📄 Description

Linked issue

Closes #1989

Why this change

  • The card CSS sanitizer (src/shared/lib/chat-css.ts) is a regex blocklist over raw text. CSS escape sequences (\XX hex, \c) are decoded by the engine, so a guard that matches literal keyword text can be bypassed by spelling the token with escapes. Examples: \75rl(https://tracker.test) bypasses the url() network guard, po\73ition: fixed bypasses the overlay guard, --back\67round bypasses the theme-token blocklist, and :h\61s( re-enables scope probing.

What changed

  • Add canonicalizeKeywordEscapes(), a string-aware pass at the top of sanitizeChatCss that decodes browser-equivalent escapes for token characters before the existing guards run.
  • Decode escapes resolving to ASCII letters, @, or -, so guards see escaped url(), at-rules, position: fixed, content, !important, theme tokens, and -moz-binding as the browser parses them.
  • Preserve escapes resolving to digits or other punctuation, plus all escapes inside string literals, so benign selectors such as .\32 xl and .w-1\/2 remain byte-exact.

Refactor impact

Primary owner: shared lib (card CSS sanitizer)

Impact areas reviewed:

  • src/shared/lib/chat-css.ts - change is confined to sanitizeChatCss; scopeChatCss and filterCssByMode behavior is unchanged.

Boundary notes:

  • Shared lib only. No engine, shared-API, Rust, remote-runtime, or feature-layer changes.

Pressure points touched:

  • None. No ModeSurface, GameSurface, shared mode UI, src-tauri/src/lib.rs command registration, or import modules touched.

Validation

  • Matching validation command passes locally (for example pnpm typecheck, pnpm build, pnpm check:architecture, pnpm check:docs, or full pnpm check when warranted)
  • Full pnpm check passes before PR push/handoff
  • Human/manual validation completed by contributor or reviewer

Manual verification notes

Run locally on the cleaned candidate:

  • pnpm --dir C:/tmp/marinara-pr-2020-clean exec vitest run src/shared/lib/chat-css.proof.test.ts - clean, 3 proof rows passed from ignored scratch proof
  • pnpm --dir C:/tmp/marinara-pr-2020-clean typecheck - clean
  • pnpm --dir C:/tmp/marinara-pr-2020-clean check:architecture - clean, no dependency violations
  • pnpm --dir C:/tmp/marinara-pr-2020-clean check - clean

Proof rows covered:

  • Escaped forbidden constructs are neutralized: url(), @import, :has(), position: fixed, content, and !important.
  • Escaped hyphen declaration bypasses are neutralized: theme-token declarations and -moz-binding.
  • Benign selector and string escapes are preserved: .w-1\/2, .\32 xl, non-theme custom properties, and string contents.

Feature Discoverability

  • Updated src/features/shell/discovery/ because this PR adds or materially changes a user-discoverable feature, workflow, setting, mode, panel, import path, agent, media capability, or advanced tool.
  • N/A because this PR is only a bugfix, refactor, test, docs, internal wiring, visual polish, copy edit, or compatibility fix and does not add a new thing users need to find.

Reason:

  • N/A - this hardens the existing CSS sanitizer against escape-based evasion. Legitimate card CSS behaves identically; there is no new user-discoverable surface.

Docs and release impact

  • No docs changes needed
  • Updated README.md
  • Updated CONTRIBUTING.md
  • Updated docs/developer/
  • Updated repo skills or AGENTS.md
  • Confirmed this PR does not restore old staging/package-workspace/release claims

UI evidence

N/A - internal sanitizer hardening with no visible UI change.


🔄 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/2020 **Author:** [@kolacheee](https://github.com/kolacheee) **Created:** 6/3/2026 **Status:** ✅ Merged **Merged:** 6/4/2026 **Merged by:** [@cha1latte](https://github.com/cha1latte) **Base:** `refactor` ← **Head:** `fix/card-css-escape-sanitizer` --- ### 📝 Commits (1) - [`7569011`](https://github.com/Pasta-Devs/Marinara-Engine/commit/7569011c5da00499fa0ebccc56b5566fc596d23b) Harden card CSS sanitizer against escape evasion ### 📊 Changes **1 file changed** (+48 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `src/shared/lib/chat-css.ts` (+48 -0) </details> ### 📄 Description ## Linked issue Closes #1989 ## Why this change - The card CSS sanitizer (`src/shared/lib/chat-css.ts`) is a regex blocklist over raw text. CSS escape sequences (`\XX` hex, `\c`) are decoded by the engine, so a guard that matches literal keyword text can be bypassed by spelling the token with escapes. Examples: `\75rl(https://tracker.test)` bypasses the `url()` network guard, `po\73ition: fixed` bypasses the overlay guard, `--back\67round` bypasses the theme-token blocklist, and `:h\61s(` re-enables scope probing. ## What changed - Add `canonicalizeKeywordEscapes()`, a string-aware pass at the top of `sanitizeChatCss` that decodes browser-equivalent escapes for token characters before the existing guards run. - Decode escapes resolving to ASCII letters, `@`, or `-`, so guards see escaped `url()`, at-rules, `position: fixed`, `content`, `!important`, theme tokens, and `-moz-binding` as the browser parses them. - Preserve escapes resolving to digits or other punctuation, plus all escapes inside string literals, so benign selectors such as `.\32 xl` and `.w-1\/2` remain byte-exact. ## Refactor impact Primary owner: shared lib (card CSS sanitizer) Impact areas reviewed: - `src/shared/lib/chat-css.ts` - change is confined to `sanitizeChatCss`; `scopeChatCss` and `filterCssByMode` behavior is unchanged. Boundary notes: - Shared lib only. No engine, shared-API, Rust, remote-runtime, or feature-layer changes. Pressure points touched: - None. No ModeSurface, GameSurface, shared mode UI, `src-tauri/src/lib.rs` command registration, or import modules touched. ## Validation - [x] Matching validation command passes locally (for example `pnpm typecheck`, `pnpm build`, `pnpm check:architecture`, `pnpm check:docs`, or full `pnpm check` when warranted) - [x] Full `pnpm check` passes before PR push/handoff - [ ] Human/manual validation completed by contributor or reviewer ### Manual verification notes Run locally on the cleaned candidate: - `pnpm --dir C:/tmp/marinara-pr-2020-clean exec vitest run src/shared/lib/chat-css.proof.test.ts` - clean, 3 proof rows passed from ignored scratch proof - `pnpm --dir C:/tmp/marinara-pr-2020-clean typecheck` - clean - `pnpm --dir C:/tmp/marinara-pr-2020-clean check:architecture` - clean, no dependency violations - `pnpm --dir C:/tmp/marinara-pr-2020-clean check` - clean Proof rows covered: - Escaped forbidden constructs are neutralized: `url()`, `@import`, `:has()`, `position: fixed`, `content`, and `!important`. - Escaped hyphen declaration bypasses are neutralized: theme-token declarations and `-moz-binding`. - Benign selector and string escapes are preserved: `.w-1\/2`, `.\32 xl`, non-theme custom properties, and string contents. ## Feature Discoverability - [ ] Updated `src/features/shell/discovery/` because this PR adds or materially changes a user-discoverable feature, workflow, setting, mode, panel, import path, agent, media capability, or advanced tool. - [x] N/A because this PR is only a bugfix, refactor, test, docs, internal wiring, visual polish, copy edit, or compatibility fix and does not add a new thing users need to find. Reason: - N/A - this hardens the existing CSS sanitizer against escape-based evasion. Legitimate card CSS behaves identically; there is no new user-discoverable surface. ## Docs and release impact - [x] No docs changes needed - [ ] Updated `README.md` - [ ] Updated `CONTRIBUTING.md` - [ ] Updated `docs/developer/` - [ ] Updated repo skills or `AGENTS.md` - [x] Confirmed this PR does not restore old staging/package-workspace/release claims ## UI evidence N/A - internal sanitizer hardening with no visible UI change. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-22 04:15:54 +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#5392
No description provided.