mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #2947] [Issue]: Themes don't get the size cap or access gate that extensions do #1525
Labels
No labels
android
bug
bugfix
ci
client
code freeze pause
container
dependencies
docs
documentation
duplicate
enhancement
feature
feature
feature
feature-creep
fixed-in-refactor
fixed-in-staging
good first issue
help wanted
in-pr
in-pr
needs-codeowner-decision
normal-scope
old-codebase
old-codebase
pull-request
qol
question
refactor
regression
revisit later
roadmap
scope-risk
scope-risk
server
server
shared
soup
upstream
windows
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Pasta-Devs/Marinara-Engine#1525
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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:
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
cssat all. A multi-megabyte theme passes validation, is stored verbatim in SQLite, is re-sent on everyGET /themes(the client auto-refetches every 15s), and is re-parsed into a<style>on activation.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):
POST /api/themeswith acssfield of ~50 MB (e.g. a giant CSS comment), or paste a huge blob into the theme editor and Save.GET /themes(including the 15s auto-refetch) ships the whole payload.Expected: theme
cssis byte-capped like extension CSS (e.g. 256 KiB), returning a 400 past the cap.Access gate (only after the private-network opt-in):
ALLOW_UNAUTHENTICATED_PRIVATE_NETWORK=true(or add the peer toIP_ALLOWLIST).POST /api/themes {name, css}thenPUT /api/themes/active— both return 200 with no privileged-access challenge, whereasPOST /api/extensionsreturns 403 in the same setup.Expected: theme write/activate routes honor the same privileged-access posture as extension routes.
Where it is
packages/shared/src/schemas/theme.schema.ts:8(css: z.string().default("")) and:15(css: z.string().optional()) — no.max()/byte refine. Contrastpackages/shared/src/schemas/extension.schema.ts:9-10,43-44,53-54, which caps both via autf8ByteLengthrefine. Stored verbatim inthemes.storage.ts.packages/server/src/routes/themes.routes.ts— POST (15), PATCH (20), DELETE (27), PUT/active(34) have norequirePrivilegedAccess. Contrastpackages/server/src/routes/extensions.routes.ts:24,30,41, which gates every write.What's happening
The size-cap refine and the
requirePrivilegedAccessguard that were added to the extension schema/routes were simply never mirrored onto the theme schema/routes.Suggested fix
utf8ByteLength+ byte-limit refine fromextension.schema.tsinto a shared helper and apply it (e.g. 256 KiB) tocreateThemeSchema.cssandupdateThemeSchema.css.requirePrivilegedAccessto 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.
@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.