[GH-ISSUE #2947] [Issue]: Themes don't get the size cap or access gate that extensions do #1525

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

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

Originally assigned to: @SpicyMarinara on GitHub.

What's wrong

The extension system was deliberately hardened in two ways that the theme system never got, even though both store user content that gets injected into the page. Themes are missing both protections:

  1. No size cap. The extension schema byte-caps CSS at 256 KiB and JS at 1 MiB, with a comment explaining that an unbounded payload "would be a real DoS surface." The theme schema has no cap on css at all. A multi-megabyte theme passes validation, is stored verbatim in SQLite, is re-sent on every GET /themes (the client auto-refetches every 15s), and is re-parsed into a <style> on activation.

  2. No access gate. Every extension write route requires privileged access (loopback or ADMIN_SECRET). The theme write/activate routes have none. By default the server already fails closed for non-loopback peers, so this only bites when an operator has explicitly opted into passwordless private-network access — but in that setup a second device on the LAN/Tailscale can create and activate a theme while the same device is correctly refused for extensions. (And because theme CSS is injected raw — see the separate theme-CSS issue — an activated theme isn't purely cosmetic.)

Neither is catastrophic on its own; together they're a clear "themes didn't inherit the hardening extensions got" gap, and both fixes are small.

How to reproduce (try it yourself)

Size cap (always reproducible on localhost):

  1. POST /api/themes with a css field of ~50 MB (e.g. a giant CSS comment), or paste a huge blob into the theme editor and Save.
  2. The create returns 200 and persists — no 400/413. Every later GET /themes (including the 15s auto-refetch) ships the whole payload.
    Expected: theme css is byte-capped like extension CSS (e.g. 256 KiB), returning a 400 past the cap.

Access gate (only after the private-network opt-in):

  1. Set ALLOW_UNAUTHENTICATED_PRIVATE_NETWORK=true (or add the peer to IP_ALLOWLIST).
  2. From a second device: POST /api/themes {name, css} then PUT /api/themes/active — both return 200 with no privileged-access challenge, whereas POST /api/extensions returns 403 in the same setup.
    Expected: theme write/activate routes honor the same privileged-access posture as extension routes.

Where it is

  • Size cap: packages/shared/src/schemas/theme.schema.ts:8 (css: z.string().default("")) and :15 (css: z.string().optional()) — no .max()/byte refine. Contrast packages/shared/src/schemas/extension.schema.ts:9-10,43-44,53-54, which caps both via a utf8ByteLength refine. Stored verbatim in themes.storage.ts.
  • Access gate: packages/server/src/routes/themes.routes.ts — POST (15), PATCH (20), DELETE (27), PUT /active (34) have no requirePrivilegedAccess. Contrast packages/server/src/routes/extensions.routes.ts:24,30,41, which gates every write.

What's happening

The size-cap refine and the requirePrivilegedAccess guard that were added to the extension schema/routes were simply never mirrored onto the theme schema/routes.

Suggested fix

  • Extract the utf8ByteLength + byte-limit refine from extension.schema.ts into a shared helper and apply it (e.g. 256 KiB) to createThemeSchema.css and updateThemeSchema.css.
  • Add requirePrivilegedAccess to the four theme write/activate routes so the privilege posture matches extensions.

AI-investigated against v2.0.6; cited lines were read. Please confirm before fixing.

Originally created by @kolacheee on GitHub (Jun 28, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2947 Originally assigned to: @SpicyMarinara on GitHub. **What's wrong** The extension system was deliberately hardened in two ways that the theme system never got, even though both store user content that gets injected into the page. Themes are missing both protections: 1. **No size cap.** The extension schema byte-caps CSS at 256 KiB and JS at 1 MiB, with a comment explaining that an unbounded payload "would be a real DoS surface." The theme schema has **no** cap on `css` at all. A multi-megabyte theme passes validation, is stored verbatim in SQLite, is re-sent on every `GET /themes` (the client auto-refetches every 15s), and is re-parsed into a `<style>` on activation. 2. **No access gate.** Every extension write route requires privileged access (loopback or `ADMIN_SECRET`). The theme write/activate routes have **none**. By default the server already fails closed for non-loopback peers, so this only bites when an operator has explicitly opted into passwordless private-network access — but in that setup a second device on the LAN/Tailscale can create and activate a theme while the same device is correctly refused for extensions. (And because theme CSS is injected raw — see the separate theme-CSS issue — an activated theme isn't purely cosmetic.) Neither is catastrophic on its own; together they're a clear "themes didn't inherit the hardening extensions got" gap, and both fixes are small. **How to reproduce (try it yourself)** Size cap (always reproducible on localhost): 1. `POST /api/themes` with a `css` field of ~50 MB (e.g. a giant CSS comment), or paste a huge blob into the theme editor and Save. 2. The create returns 200 and persists — no 400/413. Every later `GET /themes` (including the 15s auto-refetch) ships the whole payload. **Expected:** theme `css` is byte-capped like extension CSS (e.g. 256 KiB), returning a 400 past the cap. Access gate (only after the private-network opt-in): 1. Set `ALLOW_UNAUTHENTICATED_PRIVATE_NETWORK=true` (or add the peer to `IP_ALLOWLIST`). 2. From a second device: `POST /api/themes {name, css}` then `PUT /api/themes/active` — both return 200 with no privileged-access challenge, whereas `POST /api/extensions` returns 403 in the same setup. **Expected:** theme write/activate routes honor the same privileged-access posture as extension routes. **Where it is** - Size cap: `packages/shared/src/schemas/theme.schema.ts:8` (`css: z.string().default("")`) and `:15` (`css: z.string().optional()`) — no `.max()`/byte refine. Contrast `packages/shared/src/schemas/extension.schema.ts:9-10,43-44,53-54`, which caps both via a `utf8ByteLength` refine. Stored verbatim in `themes.storage.ts`. - Access gate: `packages/server/src/routes/themes.routes.ts` — POST (15), PATCH (20), DELETE (27), PUT `/active` (34) have no `requirePrivilegedAccess`. Contrast `packages/server/src/routes/extensions.routes.ts:24,30,41`, which gates every write. **What's happening** The size-cap refine and the `requirePrivilegedAccess` guard that were added to the extension schema/routes were simply never mirrored onto the theme schema/routes. **Suggested fix** - Extract the `utf8ByteLength` + byte-limit refine from `extension.schema.ts` into a shared helper and apply it (e.g. 256 KiB) to `createThemeSchema.css` and `updateThemeSchema.css`. - Add `requirePrivilegedAccess` to the four theme write/activate routes so the privilege posture matches extensions. --- *AI-investigated against v2.0.6; cited lines were read. Please confirm before fixing.*
Author
Owner

@SpicyMarinara commented on GitHub (Jun 28, 2026):

Fixed on staging: theme write/activation routes now require privileged access like extensions, and theme CSS has the same 256 KiB byte cap.

<!-- gh-comment-id:4827784594 --> @SpicyMarinara commented on GitHub (Jun 28, 2026): Fixed on staging: theme write/activation routes now require privileged access like extensions, and theme CSS has the same 256 KiB byte cap.
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#1525
No description provided.