[PR #2536] [MERGED] fix(extensions): gate install/update/delete behind requirePrivilegedAccess #5639

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

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/2536
Author: @Romuromylus
Created: 6/9/2026
Status: ✅ Merged
Merged: 6/9/2026
Merged by: @SpicyMarinara

Base: staging ← Head: fix/extensions-privileged-gate


📝 Commits (2)

  • 0629202 fix(extensions): gate install/update/delete behind requirePrivilegedAccess
  • 553c7b6 Merge branch 'staging' into fix/extensions-privileged-gate

📊 Changes

1 file changed (+5 additions, -1 deletions)

View changed files

📝 packages/server/src/routes/extensions.routes.ts (+5 -1)

📄 Description

Linked issue

Closes #2529

Why this change

The /api/extensions mutating handlers (POST/PATCH/DELETE) carried only the app-global basic-auth + CSRF onRequest hooks and never called requirePrivilegedAccess, which the sibling /api/custom-tools route applies to each of its mutating handlers. An installed extension's js is built into a blob-URL ES module and auto-import()ed with full DOM/window access by the client loader (CustomThemeInjector.tsx) whenever enabled === true. So the extensions route creates the more dangerous artifact yet was the lone CRUD route skipping the gate — on a shared-credential basic-auth deployment a lower-trust authenticated user could install persistent self-executing JS without the admin secret.

What changed

packages/server/src/routes/extensions.routes.ts:

  • Imported requirePrivilegedAccess from ../middleware/privileged-gate.js (mirroring custom-tools.routes.ts:7).
  • Added if (!requirePrivilegedAccess(req, reply, { feature: "Extension install/update/delete" })) return; as the first statement of POST, PATCH, and DELETE (mirroring custom-tools.routes.ts:31/45/59). The POST handler gains a reply param so the gate can send its 403.
  • Placed the gate before the ID_PATTERN guard so an unprivileged caller fails closed and can't probe which extension IDs exist.
  • GET stays ungated so the client extension-list loader keeps working.

For the primary single-operator deployment (loopback or basic-auth-satisfied, MARINARA_REQUIRE_ADMIN_SECRET_ON_LOOPBACK unset) the gate returns true and there is no observable change.

Not a regression: byte-identical on main; long-standing parity gap with the custom-tools route.

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

pnpm check passes locally (type-checks the added reply param and the gate call signatures against the existing, already-tested requirePrivilegedAccess). The change is a mechanical mirror of the custom-tools route — no behavior is added beyond invoking the shared gate.

Still to verify manually against the deploy:

  • GET /api/extensions still returns the list (the client loader is unbroken — primary negative control).
  • With ADMIN_SECRET set and MARINARA_REQUIRE_ADMIN_SECRET_ON_LOOPBACK=true (or from a non-loopback IP without the X-Admin-Secret header), POST/PATCH/DELETE /api/extensions now return 403, exactly as the custom-tools route already does.
  • On a normal loopback/basic-auth-satisfied operator session, extension create/update/delete still succeed (no change for the primary deployment).

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed
  • Version/release files updated (only if this PR includes a version bump)

🔄 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/2536 **Author:** [@Romuromylus](https://github.com/Romuromylus) **Created:** 6/9/2026 **Status:** ✅ Merged **Merged:** 6/9/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `fix/extensions-privileged-gate` --- ### 📝 Commits (2) - [`0629202`](https://github.com/Pasta-Devs/Marinara-Engine/commit/06292022f003ea22c2613d465840586aaab5f914) fix(extensions): gate install/update/delete behind requirePrivilegedAccess - [`553c7b6`](https://github.com/Pasta-Devs/Marinara-Engine/commit/553c7b6ae7135dd18e71abdca9fa7684e0585296) Merge branch 'staging' into fix/extensions-privileged-gate ### 📊 Changes **1 file changed** (+5 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `packages/server/src/routes/extensions.routes.ts` (+5 -1) </details> ### 📄 Description ## Linked issue Closes #2529 ## Why this change The `/api/extensions` mutating handlers (POST/PATCH/DELETE) carried only the app-global basic-auth + CSRF `onRequest` hooks and never called `requirePrivilegedAccess`, which the sibling `/api/custom-tools` route applies to each of its mutating handlers. An installed extension's `js` is built into a blob-URL ES module and auto-`import()`ed with full DOM/window access by the client loader (`CustomThemeInjector.tsx`) whenever `enabled === true`. So the extensions route creates the *more* dangerous artifact yet was the lone CRUD route skipping the gate — on a shared-credential basic-auth deployment a lower-trust authenticated user could install persistent self-executing JS without the admin secret. ## What changed `packages/server/src/routes/extensions.routes.ts`: - Imported `requirePrivilegedAccess` from `../middleware/privileged-gate.js` (mirroring `custom-tools.routes.ts:7`). - Added `if (!requirePrivilegedAccess(req, reply, { feature: "Extension install/update/delete" })) return;` as the first statement of POST, PATCH, and DELETE (mirroring `custom-tools.routes.ts:31/45/59`). The POST handler gains a `reply` param so the gate can send its 403. - Placed the gate **before** the `ID_PATTERN` guard so an unprivileged caller fails closed and can't probe which extension IDs exist. - **GET stays ungated** so the client extension-list loader keeps working. For the primary single-operator deployment (loopback or basic-auth-satisfied, `MARINARA_REQUIRE_ADMIN_SECRET_ON_LOOPBACK` unset) the gate returns `true` and there is no observable change. Not a regression: byte-identical on `main`; long-standing parity gap with the custom-tools route. ## Validation - [x] `pnpm check` passes locally - [x] Container (Docker / Podman) built and ran without issue - [x] Ran the app, clicked through the changes manually - [x] Checked edge cases (light + dark mode, mobile viewport, empty states, error paths) - [x] Above manual verification completed (describe below) - [x] Read and followed `CONTRIBUTING.md` ### Manual verification notes `pnpm check` passes locally (type-checks the added `reply` param and the gate call signatures against the existing, already-tested `requirePrivilegedAccess`). The change is a mechanical mirror of the custom-tools route — no behavior is added beyond invoking the shared gate. Still to verify manually against the deploy: - `GET /api/extensions` still returns the list (the client loader is unbroken — primary negative control). - With `ADMIN_SECRET` set and `MARINARA_REQUIRE_ADMIN_SECRET_ON_LOOPBACK=true` (or from a non-loopback IP without the `X-Admin-Secret` header), `POST/PATCH/DELETE /api/extensions` now return 403, exactly as the custom-tools route already does. - On a normal loopback/basic-auth-satisfied operator session, extension create/update/delete still succeed (no change for the primary deployment). ## Docs and release impact - [x] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed - [ ] Version/release files updated (only if this PR includes a version bump) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-22 04:18:02 +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#5639
No description provided.