[GH-ISSUE #3603] [Issue]: Remote admin folder picker omits the configured admin header #1949

Closed
opened 2026-10-21 05:44:04 +07:00 by bsakaguchi · 2 comments
Owner

Originally created by @Xelvanis on GitHub (Jul 14, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/3603

Originally assigned to: @SpicyMarinara on GitHub.

Summary

Remote administrators cannot use Agent Editor's custom-music folder picker even after correctly configuring and saving ADMIN_SECRET. The picker calls the privileged endpoint with direct fetch(), so it omits the X-Admin-Secret header that Marinara's shared API client normally supplies.

This is one confirmed user-facing instance of a wider client architecture problem: the current client contains 52 direct internal /api fetches across 12 modules despite the documented requirement to use api.* from @/lib/api-client.

Expected behavior

After a remote user saves the matching secret under Settings → Advanced → Admin Access, selecting a custom music folder should send that secret through Marinara's shared API client and open the server-side folder picker.

Actual behavior

AgentEditor calls POST /api/game-assets/pick-local-music-folder with direct fetch() and only a Content-Type header. The route intentionally calls requirePrivilegedAccess(...), so a non-loopback request is rejected with HTTP 403 and Invalid or missing X-Admin-Secret header even though the browser has a valid saved admin secret.

The server is failing closed as intended; the client simply does not attach the configured credentials for this call.

Steps to reproduce

  1. Serve Marinara for access from another device, configure Basic Auth and ADMIN_SECRET, and open it from a non-loopback browser.
  2. In Settings → Advanced → Admin Access, save the same admin secret.
  3. Open Agent Editor, configure custom music to use an external folder, and click the folder-selection action.
  4. Observe that POST /api/game-assets/pick-local-music-folder returns HTTP 403 with Invalid or missing X-Admin-Secret header instead of opening the folder picker.

Environment

  • Marinara Engine version: 2.2.2 (bcd4e836)
  • Install type: source
  • OS + version: Windows 11 Pro 10.0.26200 (build 26200)
  • Browser or app shell: remote browser/non-loopback client

Logs, screenshots, or video

Relevant client call:

const res = await fetch("/api/game-assets/pick-local-music-folder", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
});

Relevant server response path:

403 Invalid or missing X-Admin-Secret header

This was confirmed from the request and authorization paths; it has not been manually reproduced against a separate remote device.

Additional context

Focused fix

Route this request through the existing shared client, for example api.post<{ success: boolean; path: string }>("/game-assets/pick-local-music-folder"). apiFetch() already attaches the saved X-Admin-Secret, adds the CSRF header for unsafe methods, disables caching, and normalizes error handling.

Related closed issue: #3055 addressed server-side access around local music files. This report is different: the picker is correctly privileged, but its legitimate remote-admin client does not send the configured credential.

Wider direct-fetch inventory

The same audit found 52 direct internal /api fetches across 12 modules:

Module Calls
components/bot-browser/BotBrowserView.tsx 25
components/agents/AgentEditor.tsx 11
components/modals/STBulkImportModal.tsx 4
components/panels/SettingsPanel.tsx 3
hooks/use-scene-analysis.ts 2
App.tsx 1
components/chat/ChatBranchSelector.tsx 1
components/layout/ChatSidebar.tsx 1
components/ui/GifPicker.tsx 1
hooks/use-knowledge-sources.ts 1
lib/tts-service.ts 1
stores/chat.store.ts 1

Not every direct call is necessarily producing a visible bug today, and raw/streaming responses may need api.raw() rather than the normal JSON helpers. However, all direct internal calls bypass some combination of shared admin headers, CSRF headers, cache: "no-store", fallback-header handling, and normalized errors.

The client instructions already say: “Don't use fetch() directly. Always use api.* from @/lib/api-client.” The smallest sustainable follow-up is incremental migration using api.raw, api.upload, or the normal helpers, followed by an ESLint restriction preventing direct internal /api fetches outside api-client.ts.

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 @Xelvanis on GitHub (Jul 14, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/3603 Originally assigned to: @SpicyMarinara on GitHub. ## Summary Remote administrators cannot use Agent Editor's custom-music folder picker even after correctly configuring and saving `ADMIN_SECRET`. The picker calls the privileged endpoint with direct `fetch()`, so it omits the `X-Admin-Secret` header that Marinara's shared API client normally supplies. This is one confirmed user-facing instance of a wider client architecture problem: the current client contains 52 direct internal `/api` fetches across 12 modules despite the documented requirement to use `api.*` from `@/lib/api-client`. ## Expected behavior After a remote user saves the matching secret under **Settings → Advanced → Admin Access**, selecting a custom music folder should send that secret through Marinara's shared API client and open the server-side folder picker. ## Actual behavior `AgentEditor` calls `POST /api/game-assets/pick-local-music-folder` with direct `fetch()` and only a `Content-Type` header. The route intentionally calls `requirePrivilegedAccess(...)`, so a non-loopback request is rejected with HTTP 403 and `Invalid or missing X-Admin-Secret header` even though the browser has a valid saved admin secret. The server is failing closed as intended; the client simply does not attach the configured credentials for this call. ## Steps to reproduce 1. Serve Marinara for access from another device, configure Basic Auth and `ADMIN_SECRET`, and open it from a non-loopback browser. 2. In **Settings → Advanced → Admin Access**, save the same admin secret. 3. Open Agent Editor, configure custom music to use an external folder, and click the folder-selection action. 4. Observe that `POST /api/game-assets/pick-local-music-folder` returns HTTP 403 with `Invalid or missing X-Admin-Secret header` instead of opening the folder picker. ## Environment - Marinara Engine version: 2.2.2 (`bcd4e836`) - Install type: source - OS + version: Windows 11 Pro 10.0.26200 (build 26200) - Browser or app shell: remote browser/non-loopback client ## Logs, screenshots, or video Relevant client call: ```ts const res = await fetch("/api/game-assets/pick-local-music-folder", { method: "POST", headers: { "Content-Type": "application/json" }, }); ``` Relevant server response path: ```text 403 Invalid or missing X-Admin-Secret header ``` This was confirmed from the request and authorization paths; it has not been manually reproduced against a separate remote device. ## Additional context ### Focused fix Route this request through the existing shared client, for example `api.post<{ success: boolean; path: string }>("/game-assets/pick-local-music-folder")`. `apiFetch()` already attaches the saved `X-Admin-Secret`, adds the CSRF header for unsafe methods, disables caching, and normalizes error handling. Related closed issue: #3055 addressed server-side access around local music files. This report is different: the picker is correctly privileged, but its legitimate remote-admin client does not send the configured credential. ### Wider direct-fetch inventory The same audit found **52 direct internal `/api` fetches across 12 modules**: | Module | Calls | | --- | ---: | | `components/bot-browser/BotBrowserView.tsx` | 25 | | `components/agents/AgentEditor.tsx` | 11 | | `components/modals/STBulkImportModal.tsx` | 4 | | `components/panels/SettingsPanel.tsx` | 3 | | `hooks/use-scene-analysis.ts` | 2 | | `App.tsx` | 1 | | `components/chat/ChatBranchSelector.tsx` | 1 | | `components/layout/ChatSidebar.tsx` | 1 | | `components/ui/GifPicker.tsx` | 1 | | `hooks/use-knowledge-sources.ts` | 1 | | `lib/tts-service.ts` | 1 | | `stores/chat.store.ts` | 1 | Not every direct call is necessarily producing a visible bug today, and raw/streaming responses may need `api.raw()` rather than the normal JSON helpers. However, all direct internal calls bypass some combination of shared admin headers, CSRF headers, `cache: "no-store"`, fallback-header handling, and normalized errors. The client instructions already say: **“Don't use `fetch()` directly. Always use `api.*` from `@/lib/api-client`.”** The smallest sustainable follow-up is incremental migration using `api.raw`, `api.upload`, or the normal helpers, followed by an ESLint restriction preventing direct internal `/api` fetches outside `api-client.ts`. ## 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.
bsakaguchi 2026-10-21 05:44:04 +07:00
Author
Owner

@SpicyMarinara commented on GitHub (Jul 14, 2026):

Claimed by @SpicyMarinara. I’m routing the Agent Editor folder-picker request through the shared authenticated API client so remote admin and CSRF headers are attached, with a focused regression guard against direct fetch for this privileged endpoint.

<!-- gh-comment-id:4968990156 --> @SpicyMarinara commented on GitHub (Jul 14, 2026): Claimed by @SpicyMarinara. I’m routing the Agent Editor folder-picker request through the shared authenticated API client so remote admin and CSRF headers are attached, with a focused regression guard against direct fetch for this privileged endpoint.
Author
Owner

@SpicyMarinara commented on GitHub (Jul 14, 2026):

Fixed in #3605 and merged to staging as acc3d3b22. The privileged Agent Editor folder picker now uses the shared API client, attaching the configured remote-admin and CSRF headers. Focused regression coverage, full checks, UI smoke, container build, and CodeRabbit review passed.

<!-- gh-comment-id:4969072815 --> @SpicyMarinara commented on GitHub (Jul 14, 2026): Fixed in #3605 and merged to `staging` as `acc3d3b22`. The privileged Agent Editor folder picker now uses the shared API client, attaching the configured remote-admin and CSRF headers. Focused regression coverage, full checks, UI smoke, container build, and CodeRabbit review passed.
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#1949
No description provided.