[PR #8773] [MERGED] fix(extensions): keep the sandbox document opaque-origin everywhere #8797

Closed
opened 2026-11-07 17:39:46 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/8773
Author: @SpicyMarinara
Created: 11/3/2026
Status: ✅ Merged
Merged: 11/3/2026
Merged by: @SpicyMarinara

Base: staging ← Head: fix/hardening-extension-sandbox-page


📝 Commits (1)

  • 7a390b9 fix(extensions): keep the sandbox document opaque-origin everywhere

📊 Changes

4 files changed (+41 additions, -3 deletions)

View changed files

📝 packages/client/src/lib/slash-commands.ts (+8 -1)
📝 packages/server/src/routes/personal-extensions.routes.ts (+2 -1)
📝 scripts/regressions/extension-dice-formats.regression.ts (+13 -1)
📝 scripts/regressions/extension-security.regression.ts (+18 -0)

📄 Description

Important

Contributions target staging. Only SpicyMarinara may promote this repository's staging branch or a same-repository hotfix/* branch to main.

Linked issue

Closes #8769

Why this change

A sandboxed (not full-page) Browser Extension is approved as the isolated kind: no page, DOM, origin storage or network. Its sandbox document got that isolation only from the client's iframe sandbox attribute. The document's own Content-Security-Policy had no sandbox directive, so opened any other way it ran in Marinara's origin. Separately, plainDiceText claimed to make extension dice text plain, but backslashes do not stop HTML, and the chat renderer decodes entity-encoded tags back into HTML. Extension text in a /roll message could therefore carry markup.

What changed

  • Nothing that worked before stops working. Sandboxed Browser Extensions still start and run in their iframe; this was checked in Chromium and WebKit.
  • The sandbox document for sandboxed Browser Extensions is now served with sandbox allow-scripts in its Content-Security-Policy, matching the multiplayer guest document. It keeps an opaque origin wherever it loads.
  • In /roll messages, an extension's dice text and format label show <, > and & as the full-width lookalikes < > &, so that text can no longer render as HTML.
  • The extension security and dice-format regressions now check the CSP sandbox directive on a real request, and check that literal, quoted and entity-encoded tags in extension dice text stay plain.

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

  • Manually verify in the browser that an approved sandboxed Browser Extension still starts, logs and shows its windows and contributions after the change (Chromium, Safari/WebKit, and Firefox, which could not be launched here).
  • Manually verify in Firefox that the sandbox iframe still starts its blob Worker with the new CSP sandbox directive.
  • Manually verify that /roll with an extension dice format whose text or label contains < > & shows the full-width characters as plain text in chat.

Agent-run checks (for reference; each regression was shown to fail without its fix):

  • node ./scripts/pnpm-runner.mjs build:shared: completed (shared tsc build)
  • node ./scripts/run-regressions.mjs --filter extension-security (baseline, before edits): 1/1 passed
  • node ./scripts/run-regressions.mjs --filter extension-dice-formats (baseline, before edits): 1/1 passed
  • git stash push -- <2 source files>; run both regressions; git stash pop: both FAILED without the fix (CSP lacks sandbox; containsChatHtml true), both PASSED after restore
  • node ./scripts/run-regressions.mjs --filter extension-security / extension-dice-formats (with fix): 1/1 passed each
  • node ./scripts/run-regressions.mjs --filter for each of: character-identity, conversation-game-slash, convo-video-command, dice-notation (2), extension- (6), op: all passed (15 files total, 0 failed)
  • packages/server: node ../../scripts/pnpm-runner.mjs run lint (tsc -b ../shared && tsc --noEmit && tsc -p regressions character-activity): exit 0
  • packages/client: node ../../scripts/pnpm-runner.mjs run lint (eslint . + tsc client-lanes): exit 0; 0 errors, 12 pre-existing warnings, none in slash-commands.ts
  • packages/client: tsc -b (the type-check step of the client build): exit 0
  • root: tsc --noEmit -p tsconfig.json (check:e2e-types): exit 0
  • prettier --write on the 4 changed files: all unchanged (already formatted)
  • eslint packages/client/src/lib/slash-commands.ts: exit 0

Independent adversarial review: approve.

Known limits and risks:

Low. Inside the client's iframe the sandbox flags are unchanged (allow-scripts in both the attribute and the CSP), and Chromium and WebKit confirmed the worker still starts. Firefox was not tested because it would not launch here. Dice text from extensions that used <, > or & now shows full-width lookalikes instead of the ASCII characters. The regression .ts files are not covered by a repo tsconfig, so they were run with tsx but not type-checked. docs/development/personal-extensions.md still says the iframe provides the opaque origin, which remains true; no doc change was made. Out of scope for this step: the user's relayed request to make showing an outfit to a love interest in Otome Hearth pay +5 affection instead of +20. That package lives in Pasta-Devs/Marinara-Agents, not this Engine worktree, so nothing was changed for it. A read-only lookup on Agents origin/staging found the value as showHim: 20 in packages/otome-forge/src/engine/packages/client/src/features/otome-forge/shared/economy.ts:55. It is granted in .../server/src/services/otome-forge/routes/wardrobe.ts:399, and the route comment at wardrobe.ts:12 also says +20. That change needs its own Agents branch and PR.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README) as needed
  • Translated docs on the docs-i18n branch updated to match, or a [docs-i18n] follow-up issue opened (see CONTRIBUTING.md § Translated documentation)
  • Version/release files updated (only if this PR includes a version bump)

🤖 Generated with Claude Code


🔄 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/8773 **Author:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Created:** 11/3/2026 **Status:** ✅ Merged **Merged:** 11/3/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `fix/hardening-extension-sandbox-page` --- ### 📝 Commits (1) - [`7a390b9`](https://github.com/Pasta-Devs/Marinara-Engine/commit/7a390b911b29c361f405703863bb344186ee5871) fix(extensions): keep the sandbox document opaque-origin everywhere ### 📊 Changes **4 files changed** (+41 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `packages/client/src/lib/slash-commands.ts` (+8 -1) 📝 `packages/server/src/routes/personal-extensions.routes.ts` (+2 -1) 📝 `scripts/regressions/extension-dice-formats.regression.ts` (+13 -1) 📝 `scripts/regressions/extension-security.regression.ts` (+18 -0) </details> ### 📄 Description > [!IMPORTANT] > Contributions target `staging`. Only `SpicyMarinara` may promote this repository's `staging` branch or a same-repository `hotfix/*` branch to `main`. ## Linked issue Closes #8769 ## Why this change A sandboxed (not full-page) Browser Extension is approved as the isolated kind: no page, DOM, origin storage or network. Its sandbox document got that isolation only from the client's iframe sandbox attribute. The document's own Content-Security-Policy had no sandbox directive, so opened any other way it ran in Marinara's origin. Separately, plainDiceText claimed to make extension dice text plain, but backslashes do not stop HTML, and the chat renderer decodes entity-encoded tags back into HTML. Extension text in a /roll message could therefore carry markup. ## What changed - Nothing that worked before stops working. Sandboxed Browser Extensions still start and run in their iframe; this was checked in Chromium and WebKit. - The sandbox document for sandboxed Browser Extensions is now served with `sandbox allow-scripts` in its Content-Security-Policy, matching the multiplayer guest document. It keeps an opaque origin wherever it loads. - In /roll messages, an extension's dice text and format label show `<`, `>` and `&` as the full-width lookalikes < > &, so that text can no longer render as HTML. - The extension security and dice-format regressions now check the CSP sandbox directive on a real request, and check that literal, quoted and entity-encoded tags in extension dice text stay plain. ## Validation <!-- These are human tasks. Never tick a box for a check that was not actually performed. --> - [ ] `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 - Manually verify in the browser that an approved sandboxed Browser Extension still starts, logs and shows its windows and contributions after the change (Chromium, Safari/WebKit, and Firefox, which could not be launched here). - Manually verify in Firefox that the sandbox iframe still starts its blob Worker with the new CSP sandbox directive. - Manually verify that /roll with an extension dice format whose text or label contains < > & shows the full-width characters as plain text in chat. Agent-run checks (for reference; each regression was shown to fail without its fix): - `node ./scripts/pnpm-runner.mjs build:shared`: completed (shared tsc build) - `node ./scripts/run-regressions.mjs --filter extension-security (baseline, before edits)`: 1/1 passed - `node ./scripts/run-regressions.mjs --filter extension-dice-formats (baseline, before edits)`: 1/1 passed - `git stash push -- <2 source files>; run both regressions; git stash pop`: both FAILED without the fix (CSP lacks sandbox; containsChatHtml true), both PASSED after restore - `node ./scripts/run-regressions.mjs --filter extension-security / extension-dice-formats (with fix)`: 1/1 passed each - `node ./scripts/run-regressions.mjs --filter for each of: character-identity, conversation-game-slash, convo-video-command, dice-notation (2), extension- (6), op`: all passed (15 files total, 0 failed) - `packages/server: node ../../scripts/pnpm-runner.mjs run lint (tsc -b ../shared && tsc --noEmit && tsc -p regressions character-activity)`: exit 0 - `packages/client: node ../../scripts/pnpm-runner.mjs run lint (eslint . + tsc client-lanes)`: exit 0; 0 errors, 12 pre-existing warnings, none in slash-commands.ts - `packages/client: tsc -b (the type-check step of the client build)`: exit 0 - `root: tsc --noEmit -p tsconfig.json (check:e2e-types)`: exit 0 - `prettier --write on the 4 changed files`: all unchanged (already formatted) - `eslint packages/client/src/lib/slash-commands.ts`: exit 0 Independent adversarial review: approve. Known limits and risks: Low. Inside the client's iframe the sandbox flags are unchanged (allow-scripts in both the attribute and the CSP), and Chromium and WebKit confirmed the worker still starts. Firefox was not tested because it would not launch here. Dice text from extensions that used `<`, `>` or `&` now shows full-width lookalikes instead of the ASCII characters. The regression .ts files are not covered by a repo tsconfig, so they were run with tsx but not type-checked. docs/development/personal-extensions.md still says the iframe provides the opaque origin, which remains true; no doc change was made. Out of scope for this step: the user's relayed request to make showing an outfit to a love interest in Otome Hearth pay +5 affection instead of +20. That package lives in Pasta-Devs/Marinara-Agents, not this Engine worktree, so nothing was changed for it. A read-only lookup on Agents origin/staging found the value as `showHim: 20` in packages/otome-forge/src/engine/packages/client/src/features/otome-forge/shared/economy.ts:55. It is granted in .../server/src/services/otome-forge/routes/wardrobe.ts:399, and the route comment at wardrobe.ts:12 also says +20. That change needs its own Agents branch and PR. ## Docs and release impact - [ ] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README) as needed - [ ] Translated docs on the `docs-i18n` branch updated to match, or a `[docs-i18n]` follow-up issue opened (see CONTRIBUTING.md § Translated documentation) - [ ] Version/release files updated (only if this PR includes a version bump) 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-07 17:39:46 +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#8797
No description provided.