[GH-ISSUE #2529] [Issue]: /api/extensions skips requirePrivilegedAccess that /api/custom-tools applies #1254

Closed
opened 2026-10-21 05:30:02 +07:00 by bsakaguchi · 0 comments
Owner

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

Originally assigned to: @Romuromylus on GitHub.

Summary

Severity: Low — security (privilege-gate asymmetry). The /api/extensions create/update/delete routes store an extension's js, which the client auto-executes in the browser when enabled is true — yet they skip requirePrivilegedAccess, the gate the sibling /api/custom-tools route applies to its less-dangerous artifacts. On a shared-credential basic-auth deployment, a lower-trust authenticated user can install persistent self-executing JS without the admin secret that creating a custom tool requires.

Expected behavior

Creating/updating/deleting a self-executing-JS extension should require at least the same trust level as creating a custom tool — i.e. requirePrivilegedAccess on the mutating handlers, matching custom-tools.routes.ts.

Actual behavior

packages/server/src/routes/extensions.routes.ts:22-25:

app.post("/", async (req) => {
  const input = createExtensionSchema.parse(req.body);
  return storage.create(input);
});

The POST/PATCH/DELETE handlers carry only the global basic-auth + CSRF hooks; none call requirePrivilegedAccess. The sibling custom-tools.routes.ts:31/45/59 gates each mutating handler with requirePrivilegedAccess, which on a non-loopback request additionally requires the ADMIN_SECRET X-Admin-Secret header (privileged-gate.ts:15-54). The extension js is the more dangerous artifact: CustomThemeInjector.tsx:109-261 builds a blob-URL ES module from ext.js and import()s it with full DOM/window access whenever ext.enabled is true, with no per-load confirmation.

Steps to reproduce

  1. On a shared web server behind basic-auth (the documented primary deployment), as a lower-trust authenticated, same-origin user, POST /api/extensions with { name, js: "<arbitrary JS>", enabled: true }.
  2. The extension is stored with no ADMIN_SECRET required (unlike a custom tool); its JS auto-executes in every operator's browser on the next extension-list poll.

Environment

  • Marinara Engine version: 1.6.1 (staging @ a9fdae8)
  • Install type: source
  • OS + version: n/a — static source audit
  • Browser or app shell: n/a

Logs, screenshots, or video

Static source audit, cited to file:line above.

Additional context

Fix: apply requirePrivilegedAccess(req, reply, { feature: "Extension install/update/delete" }) to the POST/PATCH/DELETE handlers in extensions.routes.ts, mirroring custom-tools.routes.ts:31/45/59; keep GET ungated for the client loader. requirePrivilegedAccess is already used by the admin, backup, custom-tools, haptic, import, sidecar, and updates routes — extensions is the lone CRUD route that creates a self-executing artifact yet omits it.

Scope is Low: CSRF blocks a pure cross-site forge, so this matters only in the multi-operator shared-credential case; a single-operator install already fully trusts the operator. Filing it as the fix-pattern-already-in-repo gap it is.

Regression notes: found via static audit; extensions.routes.ts is byte-identical on main (65a0395), and main's custom-tools route already carries the gate, so the asymmetry pre-exists — not a main→staging regression.

Template check

Please uncheck (untick) the box below before submitting so we know you read the template. It is intentionally pre-checked:

  • I DID NOT read this template and provide the requested details.
Originally created by @Romuromylus on GitHub (Jun 9, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2529 Originally assigned to: @Romuromylus on GitHub. ## Summary **Severity: Low — security (privilege-gate asymmetry).** The `/api/extensions` create/update/delete routes store an extension's `js`, which the client auto-executes in the browser when `enabled` is true — yet they skip `requirePrivilegedAccess`, the gate the sibling `/api/custom-tools` route applies to its less-dangerous artifacts. On a shared-credential basic-auth deployment, a lower-trust authenticated user can install persistent self-executing JS without the admin secret that creating a custom tool requires. ## Expected behavior Creating/updating/deleting a self-executing-JS extension should require at least the same trust level as creating a custom tool — i.e. `requirePrivilegedAccess` on the mutating handlers, matching `custom-tools.routes.ts`. ## Actual behavior `packages/server/src/routes/extensions.routes.ts:22-25`: ```ts app.post("/", async (req) => { const input = createExtensionSchema.parse(req.body); return storage.create(input); }); ``` The POST/PATCH/DELETE handlers carry only the global basic-auth + CSRF hooks; none call `requirePrivilegedAccess`. The sibling `custom-tools.routes.ts:31/45/59` gates each mutating handler with `requirePrivilegedAccess`, which on a non-loopback request additionally requires the `ADMIN_SECRET` `X-Admin-Secret` header (`privileged-gate.ts:15-54`). The extension `js` is the more dangerous artifact: `CustomThemeInjector.tsx:109-261` builds a blob-URL ES module from `ext.js` and `import()`s it with full DOM/window access whenever `ext.enabled` is true, with no per-load confirmation. ## Steps to reproduce 1. On a shared web server behind basic-auth (the documented primary deployment), as a lower-trust authenticated, same-origin user, `POST /api/extensions` with `{ name, js: "<arbitrary JS>", enabled: true }`. 2. The extension is stored with no `ADMIN_SECRET` required (unlike a custom tool); its JS auto-executes in every operator's browser on the next extension-list poll. ## Environment - Marinara Engine version: 1.6.1 (`staging @ a9fdae8`) - Install type: source - OS + version: n/a — static source audit - Browser or app shell: n/a ## Logs, screenshots, or video Static source audit, cited to file:line above. ## Additional context Fix: apply `requirePrivilegedAccess(req, reply, { feature: "Extension install/update/delete" })` to the POST/PATCH/DELETE handlers in `extensions.routes.ts`, mirroring `custom-tools.routes.ts:31/45/59`; keep GET ungated for the client loader. `requirePrivilegedAccess` is already used by the admin, backup, custom-tools, haptic, import, sidecar, and updates routes — extensions is the lone CRUD route that creates a self-executing artifact yet omits it. Scope is Low: CSRF blocks a pure cross-site forge, so this matters only in the multi-operator shared-credential case; a single-operator install already fully trusts the operator. Filing it as the fix-pattern-already-in-repo gap it is. Regression notes: found via static audit; `extensions.routes.ts` is byte-identical on `main` (`65a0395`), and `main`'s custom-tools route already carries the gate, so the asymmetry pre-exists — not a `main`→`staging` regression. ## Template check Please **uncheck (untick)** the box below before submitting so we know you read the template. It is intentionally pre-checked: - [ ] I DID NOT read this template and provide the requested details.
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#1254
No description provided.