[GH-ISSUE #401] [Issue]: Backup and Export Profile return 403 on loopback after v1.5.7 privileged-gate hardening #168

Closed
opened 2026-10-20 17:25:50 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @cha1latte on GitHub (May 4, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/401

Originally assigned to: @SpicyMarinara on GitHub.

Summary

After v1.5.7's privileged-API hardening, Settings → Download Backup and Settings → Export Profile (JSON) return 403 on a fresh install, even on loopback. The new gate requires ADMIN_SECRET to be configured server-side, but there is no in-app surface for setting it and the error toast doesn't point at the cause.

Expected behavior

On a fresh install running on 127.0.0.1, clicking Download Backup should produce a backup file and clicking Export Profile (JSON) should produce a profile export, with no manual env-var setup required.

Actual behavior

Both buttons show generic failure toasts ("Failed to create backup" / "Failed to export profile"). DevTools Network tab shows:

  • GET :7860/api/backup/download → 403 Forbidden
  • GET :7860/api/backup/export-profile?format=compatible → 403 Forbidden

Response body for both:

{
  "error": "ADMIN_SECRET is required for privileged APIs",
  "message": "Set ADMIN_SECRET and send it in the X-Admin-Secret header."
}

The 403 originates from requirePrivilegedAccess in packages/server/src/middleware/privileged-gate.ts (added in f35f8a4, "Harden security defaults and privileged flows"). isBasicAuthSatisfied correctly short-circuits for loopback, but getAdminSecret() then fails because the env var is unset on a fresh install. Affected routes include backup, profile-export, profile-import, custom-tools, sidecar, updates, and import.

Client side is already wired up — getAdminSecretHeader() in packages/client/src/lib/api-client.ts reads marinara_admin_secret from localStorage and adds it as X-Admin-Secret, and Settings → Advanced → Admin Access provides a UI for setting that localStorage key. The wire format and the client-side UI are fine; what's missing is any in-app surface or prompt for the server-side ADMIN_SECRET env var, and any indication that both halves are required.

This looks like a regression rather than intended UX:

  • Settings → Advanced → Admin Access lets the user set the client-side marinara_admin_secret, but there is no in-app surface or prompt for the server-side ADMIN_SECRET env var, and no indication that both halves are required. A user who only fills in the Admin Access field still gets 403s.
  • The error toast doesn't reference admin secrets, so the user has no path to discovery without DevTools.
  • The same gate already treats loopback as authorized for basic auth; requiring an extra secret on loopback for these endpoints is internally inconsistent.
  • A local process that can reach 127.0.0.1:7860 can also read packages/server/data directly, so the gate provides no real confidentiality on loopback.

Steps to reproduce

  1. Install v1.5.7 fresh (no existing .env, no ADMIN_SECRET configured).
  2. Start Marinara via start.bat, open the UI on http://localhost:7860.
  3. Open Settings and click Download Backup (or Export Profile (JSON)).

Environment

  • Marinara Engine version: v1.5.7 (build 8325c75)
  • Install type: source (Windows installer/start.bat flow, run from G drive)
  • OS + version: Windows 11
  • Browser or app shell: Chromium-based browser (DevTools used to capture the 403 response)

Likely affects all platforms — the logic is in server middleware and is platform-independent.

Logs, screenshots, or video

Network → Response body for both failing requests:

{
  "error": "ADMIN_SECRET is required for privileged APIs",
  "message": "Set ADMIN_SECRET and send it in the X-Admin-Secret header."
}

Additional context

Ruled out:

  • CSRF guard: Fires on POST/PUT/PATCH/DELETE only, but GET /export-profile is also affected, and the response body is the admin-secret message — not CSRF's "Request origin is not trusted" / "Missing x-marinara-csrf header".
  • #394 / #396 / #398: Those were loopback/private-LAN rejection bugs in the CSRF guard, fixed by b40bb19. Different code path.
  • Filesystem permissions: Running start.bat as administrator does not help. FS errors would surface as 500, not 403.
  • Workbox non-precached-url console error: Separate sw.js bug, filed as #402 .

Proposed fix (one of):

  • Carve-out: Allow loopback requests through the privileged gate by default, gated on a new env var MARINARA_REQUIRE_ADMIN_SECRET_ON_LOOPBACK (default false) for users who want strict behavior. Non-loopback requests continue to require ADMIN_SECRET as today.
  • Bootstrap UI: Keep the gate strict, but extend the existing Admin Access field with a "Generate" button that writes ADMIN_SECRET to .env via a one-time, loopback-only bootstrap endpoint and saves the matching value to localStorage in the same action. Closes the loop without lowering the security bar.

In either case, the 403 response body should grow a machine-readable code so the toast can render something actionable instead of "Failed to create backup."

Temporary workaround:

  1. Add ADMIN_SECRET=<long random string> to .env in the install dir.
  2. Restart Marinara.
  3. In the UI, go to Settings → Advanced → Admin Access, paste the same value, and click Save.

Template check

  • I DID NOT read this template and provide the requested details.
Originally created by @cha1latte on GitHub (May 4, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/401 Originally assigned to: @SpicyMarinara on GitHub. ## Summary After v1.5.7's privileged-API hardening, `Settings → Download Backup` and `Settings → Export Profile (JSON)` return 403 on a fresh install, even on loopback. The new gate requires `ADMIN_SECRET` to be configured server-side, but there is no in-app surface for setting it and the error toast doesn't point at the cause. ## Expected behavior On a fresh install running on `127.0.0.1`, clicking Download Backup should produce a backup file and clicking Export Profile (JSON) should produce a profile export, with no manual env-var setup required. ## Actual behavior Both buttons show generic failure toasts ("Failed to create backup" / "Failed to export profile"). DevTools Network tab shows: - `GET :7860/api/backup/download` → 403 Forbidden - `GET :7860/api/backup/export-profile?format=compatible` → 403 Forbidden Response body for both: ```json { "error": "ADMIN_SECRET is required for privileged APIs", "message": "Set ADMIN_SECRET and send it in the X-Admin-Secret header." } ``` The 403 originates from `requirePrivilegedAccess` in `packages/server/src/middleware/privileged-gate.ts` (added in f35f8a4, "Harden security defaults and privileged flows"). `isBasicAuthSatisfied` correctly short-circuits for loopback, but `getAdminSecret()` then fails because the env var is unset on a fresh install. Affected routes include backup, profile-export, profile-import, custom-tools, sidecar, updates, and import. Client side is already wired up — `getAdminSecretHeader()` in `packages/client/src/lib/api-client.ts` reads `marinara_admin_secret` from localStorage and adds it as `X-Admin-Secret`, and Settings → Advanced → Admin Access provides a UI for setting that localStorage key. The wire format and the client-side UI are fine; what's missing is any in-app surface or prompt for the server-side `ADMIN_SECRET` env var, and any indication that both halves are required. This looks like a regression rather than intended UX: - Settings → Advanced → Admin Access lets the user set the client-side `marinara_admin_secret`, but there is no in-app surface or prompt for the server-side `ADMIN_SECRET` env var, and no indication that both halves are required. A user who only fills in the Admin Access field still gets 403s. - The error toast doesn't reference admin secrets, so the user has no path to discovery without DevTools. - The same gate already treats loopback as authorized for basic auth; requiring an extra secret on loopback for these endpoints is internally inconsistent. - A local process that can reach `127.0.0.1:7860` can also read `packages/server/data` directly, so the gate provides no real confidentiality on loopback. ## Steps to reproduce 1. Install v1.5.7 fresh (no existing `.env`, no `ADMIN_SECRET` configured). 2. Start Marinara via `start.bat`, open the UI on `http://localhost:7860`. 3. Open Settings and click `Download Backup` (or `Export Profile (JSON)`). ## Environment - Marinara Engine version: v1.5.7 (build 8325c75) - Install type: source (Windows installer/start.bat flow, run from G drive) - OS + version: Windows 11 - Browser or app shell: Chromium-based browser (DevTools used to capture the 403 response) Likely affects all platforms — the logic is in server middleware and is platform-independent. ## Logs, screenshots, or video Network → Response body for both failing requests: ```json { "error": "ADMIN_SECRET is required for privileged APIs", "message": "Set ADMIN_SECRET and send it in the X-Admin-Secret header." } ``` ## Additional context **Ruled out:** - **CSRF guard:** Fires on POST/PUT/PATCH/DELETE only, but `GET /export-profile` is also affected, and the response body is the admin-secret message — not CSRF's "Request origin is not trusted" / "Missing x-marinara-csrf header". - **#394 / #396 / #398:** Those were loopback/private-LAN rejection bugs in the CSRF guard, fixed by b40bb19. Different code path. - **Filesystem permissions:** Running `start.bat` as administrator does not help. FS errors would surface as 500, not 403. - **Workbox `non-precached-url` console error:** Separate sw.js bug, filed as #402 . **Proposed fix (one of):** - **Carve-out:** Allow loopback requests through the privileged gate by default, gated on a new env var `MARINARA_REQUIRE_ADMIN_SECRET_ON_LOOPBACK` (default `false`) for users who want strict behavior. Non-loopback requests continue to require `ADMIN_SECRET` as today. - **Bootstrap UI:** Keep the gate strict, but extend the existing Admin Access field with a "Generate" button that writes `ADMIN_SECRET` to `.env` via a one-time, loopback-only bootstrap endpoint and saves the matching value to localStorage in the same action. Closes the loop without lowering the security bar. In either case, the 403 response body should grow a machine-readable code so the toast can render something actionable instead of "Failed to create backup." **Temporary workaround:** 1. Add `ADMIN_SECRET=<long random string>` to `.env` in the install dir. 2. Restart Marinara. 3. In the UI, go to Settings → Advanced → Admin Access, paste the same value, and click Save. ## Template check - [ ] I DID NOT read this template and provide the requested details.
bsakaguchi 2026-10-20 17:25:50 +07:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@SpicyMarinara commented on GitHub (May 4, 2026):

Addressed in a fix.

<!-- gh-comment-id:4372561589 --> @SpicyMarinara commented on GitHub (May 4, 2026): Addressed in a fix.
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#168
No description provided.