[GH-ISSUE #3055] [Issue]: GET /local-music-file serves any audio-extension file on the host with no folder containment and without the privileged gate the folder picker requires #1623

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

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

Originally assigned to: @SpicyMarinara on GitHub.

What's wrong

The folder-picker route POST /pick-local-music-folder is protected by requirePrivilegedAccess(...), but the route that actually serves the selected files, GET /local-music-file/:encoded, is not gated at all. It base64url-decodes a fully client-controlled absolute filesystem path, checks only the file extension (must be a known audio type) and that the file exists, then streams it back. There is no assertInsideDir, no check that the path is inside the previously picked folder (the picked folder is never persisted server-side), and no privileged-access check.

An authenticated non-loopback client — a LAN device when ALLOW_UNAUTHENTICATED_PRIVATE_NETWORK=true, or anyone with the configured Basic Auth password but no admin secret — can read ANY audio-extension file anywhere on the host by supplying its absolute path base64url-encoded, even though that same client is refused the privileged folder picker.

How to reproduce (try it yourself)

  1. As an authenticated remote/LAN client (Basic Auth satisfied but not loopback, and no admin secret), call POST /api/game-assets/pick-local-music-folder.
  2. Then call GET /api/game-assets/local-music-file/<base64url of e.g. /home/user/private/secret-recording.wav>.

You'll see: step 1 returns 403 from requirePrivilegedAccess, but step 2 streams the arbitrary .wav back with an audio MIME type — exfiltrating any audio file on the host.

Expected: the serving route should be no less protected than the picker; a client refused the picker should not be able to read arbitrary host files through it.

Where it is

packages/server/src/routes/game-assets.routes.ts:

  • GET /local-music-file/:encoded lines 543-574 — unguarded; only validates extname(filePath) against MUSIC_FILE_EXTENSIONS plus existsSync/isFile, then createReadStream(filePath).
  • Contrast POST /pick-local-music-folder lines 727-728 — gated by requirePrivilegedAccess.

Gate semantics: packages/server/src/middleware/privileged-gate.ts lines 15-59. Global auth: packages/server/src/middleware/basic-auth.ts lines 313-375. Registration: packages/server/src/routes/index.ts line 102.

What's happening

The serving route trusts the client-supplied decoded absolute path entirely. The folder picker only opens a native dialog and returns the chosen path to the client; that folder is never persisted server-side, so the serving route has nothing to bound the path against. The only restriction is the audio extension, which does not limit which files can be read. The global Basic-Auth hook does not require the admin secret, so a non-loopback client passes the global hook and reaches the serving route while still being denied the privileged picker.

Suggested fix

Gate the serving route with the SAME privileged check the picker uses. In game-assets.routes.ts, as the first line inside the GET /local-music-file/:encoded handler (~line 543), mirroring the picker at line 728:

if (!requirePrivilegedAccess(req, reply, { feature: "Custom music folder picker" })) return;

requirePrivilegedAccess is already imported (line 28). For loopback desktop deployments this passes (isLoopbackIp + admin-secret not required on loopback), so legitimate playback keeps working; only non-privileged non-loopback clients (exactly the vulnerable population) are denied.

Regression avoided: do NOT add assertInsideDir(GAME_ASSETS_DIR, decodedPath) and do NOT attempt a picked-folder containment check. The legitimate feature deliberately serves absolute paths OUTSIDE GAME_ASSETS_DIR (the user-selected external music folder — see collectExternalLocalMusicTracks in agent-executor.ts:1407-1447 and LocalMusicPlayer.tsx), and the picked folder is not persisted server-side, so a containment check would break external-folder playback. One pre-existing limitation remains (not a new hole): externally-picked tracks load via an HTML audio element, which cannot send the X-Admin-Secret header, so a LAN user even with a valid admin secret still cannot play them — a fail-closed deny, which is acceptable.


AI-investigated against v2.0.6; cited lines read and confirmed. Please verify before fixing.

Originally created by @kolacheee on GitHub (Jun 29, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/3055 Originally assigned to: @SpicyMarinara on GitHub. **What's wrong** The folder-picker route `POST /pick-local-music-folder` is protected by `requirePrivilegedAccess(...)`, but the route that actually serves the selected files, `GET /local-music-file/:encoded`, is not gated at all. It base64url-decodes a fully client-controlled absolute filesystem path, checks only the file extension (must be a known audio type) and that the file exists, then streams it back. There is no `assertInsideDir`, no check that the path is inside the previously picked folder (the picked folder is never persisted server-side), and no privileged-access check. An authenticated non-loopback client — a LAN device when `ALLOW_UNAUTHENTICATED_PRIVATE_NETWORK=true`, or anyone with the configured Basic Auth password but no admin secret — can read ANY audio-extension file anywhere on the host by supplying its absolute path base64url-encoded, even though that same client is refused the privileged folder picker. **How to reproduce (try it yourself)** 1. As an authenticated remote/LAN client (Basic Auth satisfied but not loopback, and no admin secret), call `POST /api/game-assets/pick-local-music-folder`. 2. Then call `GET /api/game-assets/local-music-file/<base64url of e.g. /home/user/private/secret-recording.wav>`. You'll see: step 1 returns 403 from `requirePrivilegedAccess`, but step 2 streams the arbitrary `.wav` back with an audio MIME type — exfiltrating any audio file on the host. Expected: the serving route should be no less protected than the picker; a client refused the picker should not be able to read arbitrary host files through it. **Where it is** `packages/server/src/routes/game-assets.routes.ts`: - `GET /local-music-file/:encoded` lines 543-574 — unguarded; only validates `extname(filePath)` against `MUSIC_FILE_EXTENSIONS` plus `existsSync`/`isFile`, then `createReadStream(filePath)`. - Contrast `POST /pick-local-music-folder` lines 727-728 — gated by `requirePrivilegedAccess`. Gate semantics: `packages/server/src/middleware/privileged-gate.ts` lines 15-59. Global auth: `packages/server/src/middleware/basic-auth.ts` lines 313-375. Registration: `packages/server/src/routes/index.ts` line 102. **What's happening** The serving route trusts the client-supplied decoded absolute path entirely. The folder picker only opens a native dialog and returns the chosen path to the client; that folder is never persisted server-side, so the serving route has nothing to bound the path against. The only restriction is the audio extension, which does not limit which files can be read. The global Basic-Auth hook does not require the admin secret, so a non-loopback client passes the global hook and reaches the serving route while still being denied the privileged picker. **Suggested fix** Gate the serving route with the SAME privileged check the picker uses. In `game-assets.routes.ts`, as the first line inside the `GET /local-music-file/:encoded` handler (~line 543), mirroring the picker at line 728: ```ts if (!requirePrivilegedAccess(req, reply, { feature: "Custom music folder picker" })) return; ``` `requirePrivilegedAccess` is already imported (line 28). For loopback desktop deployments this passes (`isLoopbackIp` + admin-secret not required on loopback), so legitimate playback keeps working; only non-privileged non-loopback clients (exactly the vulnerable population) are denied. Regression avoided: do NOT add `assertInsideDir(GAME_ASSETS_DIR, decodedPath)` and do NOT attempt a picked-folder containment check. The legitimate feature deliberately serves absolute paths OUTSIDE `GAME_ASSETS_DIR` (the user-selected external music folder — see `collectExternalLocalMusicTracks` in agent-executor.ts:1407-1447 and `LocalMusicPlayer.tsx`), and the picked folder is not persisted server-side, so a containment check would break external-folder playback. One pre-existing limitation remains (not a new hole): externally-picked tracks load via an HTML `audio` element, which cannot send the `X-Admin-Secret` header, so a LAN user even with a valid admin secret still cannot play them — a fail-closed deny, which is acceptable. --- *AI-investigated against v2.0.6; cited lines read and confirmed. Please verify before fixing.*
Author
Owner

@SpicyMarinara commented on GitHub (Jun 29, 2026):

Claiming this for the current staging sweep in draft PR #3064: https://github.com/Pasta-Devs/Marinara-Engine/pull/3064

<!-- gh-comment-id:4835428565 --> @SpicyMarinara commented on GitHub (Jun 29, 2026): Claiming this for the current staging sweep in draft PR #3064: https://github.com/Pasta-Devs/Marinara-Engine/pull/3064
Author
Owner

@SpicyMarinara commented on GitHub (Jun 29, 2026):

Fixed in PR #3064 on branch codex/issue-sweep-3054-3063 (commit 3ae8ca37). Closing this issue as addressed; the PR remains open for staging review/merge.

<!-- gh-comment-id:4835577936 --> @SpicyMarinara commented on GitHub (Jun 29, 2026): Fixed in PR #3064 on branch `codex/issue-sweep-3054-3063` (commit 3ae8ca37). Closing this issue as addressed; the PR remains open for staging review/merge.
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#1623
No description provided.