[PR #8936] [MERGED] fix(server): play local music files only from the Music DJ folders #8896

Closed
opened 2026-11-07 20:43:05 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/8936
Author: @SpicyMarinara
Created: 11/7/2026
Status: ✅ Merged
Merged: 11/7/2026
Merged by: @SpicyMarinara

Base: staging ← Head: fix/local-music-file-scope


📝 Commits (3)

  • 520250a fix(server): play local music files only from the Music DJ folders (#8915)
  • 0627d75 fix(server): stream the music file that passed the folder check
  • eefb9e4 fix(server): a failed music folder recheck is a logged server error, not a silent 404

📊 Changes

3 files changed (+260 additions, -6 deletions)

View changed files

📝 packages/server/src/routes/game-assets.routes.ts (+76 -6)
📝 packages/shared/src/utils/music-dj-folder.ts (+16 -0)
➕ scripts/regressions/local-music-file-security.regression.ts (+168 -0)

📄 Description

Linked issue

Closes #8915

Why this change

GET /api/game-assets/local-music-file served any file with an audio extension, anywhere on the server's device, to anyone with privileged access. It only checked the extension and that the path was a file. It never checked that the file sits in a folder the Music DJ was told to play from: the default device folder, a character's folder or a chat's folder (#8901/#8914). Its only legitimate callers are the Music DJ's own local-music: paths and the floating player.

What changed

  • packages/shared/src/utils/music-dj-folder.ts: listMusicDjFolders(settings, chatMetadata) lists every folder the Music DJ can play from: the default folder (including the older localMusicExternalFolder key), every character folder and every chat folder. It reuses the file's existing readers.
  • packages/server/src/routes/game-assets.routes.ts:
    • The route reads the Music DJ settings (the same spotify row generation uses) and the chats' folders.
    • It resolves the real path of the file and of each folder, which resolves symlinks, .. and Windows short names. Containment is then checked with the existing isCanonicalMediaPathInsideRoot, which ignores case on Windows.
    • It streams the checked real path, not the raw input.
    • The real file must also have an audio extension, so a track-named link inside a folder can't serve another file from that folder's tree. Its MIME type comes from the real file.
  • A file outside the folders gets the same 404 { error: "Music file not found" } as a missing file, so the route can't be used to probe which files exist. The privileged gate and the other errors are unchanged.

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

Run by the agent (not a substitute for the boxes above):

  • pnpm check: exit 0.
  • New scripts/regressions/local-music-file-security.regression.ts, run against the real app (node scripts/run-regressions.mjs --filter …): 1/1.
    • Still served: a track in the default folder, in a subfolder, in a character folder that is a symlink (by link and by real path), and in a chat folder.
    • Refused with 404:
      • a file outside every folder;
      • a path that climbs out with ..;
      • a file link or folder link that leads out;
      • a sibling folder whose name starts like the default;
      • a missing file;
      • a cleared chat folder;
      • a track-named link to a file that isn't audio.
    • It fails on the old route (200 for the outside file), and the non-audio link case fails without the real-extension check.
  • --filter security (34/34), --filter music-dj, --filter local-music and --filter game-assets: pass.

Still to verify by hand:

  • Manually verify that Music DJ in Custom mode, with a default folder on this device, still plays in the floating player.
  • Manually verify that a chat folder and a character folder (Chat Settings → Music DJ → Apply to) each play their tracks.
  • Manually verify that a default folder that is a symlink, or on another disk, still plays.
  • Manually verify on Windows that a folder typed in a different letter case still plays.

Docs and release impact

  • No docs changes needed

🤖 Generated with Claude Code


🔄 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/8936 **Author:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Created:** 11/7/2026 **Status:** ✅ Merged **Merged:** 11/7/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `fix/local-music-file-scope` --- ### 📝 Commits (3) - [`520250a`](https://github.com/Pasta-Devs/Marinara-Engine/commit/520250a8b098c1db9ed25cd9a38f174c79b85840) fix(server): play local music files only from the Music DJ folders (#8915) - [`0627d75`](https://github.com/Pasta-Devs/Marinara-Engine/commit/0627d750387e9e0c543fc6df889b8195befe9412) fix(server): stream the music file that passed the folder check - [`eefb9e4`](https://github.com/Pasta-Devs/Marinara-Engine/commit/eefb9e416de2e7f9c887aaad78aa1e6e0e07ddcc) fix(server): a failed music folder recheck is a logged server error, not a silent 404 ### 📊 Changes **3 files changed** (+260 additions, -6 deletions) <details> <summary>View changed files</summary> 📝 `packages/server/src/routes/game-assets.routes.ts` (+76 -6) 📝 `packages/shared/src/utils/music-dj-folder.ts` (+16 -0) ➕ `scripts/regressions/local-music-file-security.regression.ts` (+168 -0) </details> ### 📄 Description ## Linked issue Closes #8915 ## Why this change `GET /api/game-assets/local-music-file` served any file with an audio extension, anywhere on the server's device, to anyone with privileged access. It only checked the extension and that the path was a file. It never checked that the file sits in a folder the Music DJ was told to play from: the default device folder, a character's folder or a chat's folder (#8901/#8914). Its only legitimate callers are the Music DJ's own `local-music:` paths and the floating player. ## What changed - `packages/shared/src/utils/music-dj-folder.ts`: `listMusicDjFolders(settings, chatMetadata)` lists every folder the Music DJ can play from: the default folder (including the older `localMusicExternalFolder` key), every character folder and every chat folder. It reuses the file's existing readers. - `packages/server/src/routes/game-assets.routes.ts`: - The route reads the Music DJ settings (the same `spotify` row generation uses) and the chats' folders. - It resolves the real path of the file and of each folder, which resolves symlinks, `..` and Windows short names. Containment is then checked with the existing `isCanonicalMediaPathInsideRoot`, which ignores case on Windows. - It streams the checked real path, not the raw input. - The real file must also have an audio extension, so a track-named link inside a folder can't serve another file from that folder's tree. Its MIME type comes from the real file. - A file outside the folders gets the same `404 { error: "Music file not found" }` as a missing file, so the route can't be used to probe which files exist. The privileged gate and the other errors are unchanged. ## 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 Run by the agent (not a substitute for the boxes above): - `pnpm check`: exit 0. - New `scripts/regressions/local-music-file-security.regression.ts`, run against the real app (`node scripts/run-regressions.mjs --filter …`): 1/1. - Still served: a track in the default folder, in a subfolder, in a character folder that is a symlink (by link and by real path), and in a chat folder. - Refused with 404: - a file outside every folder; - a path that climbs out with `..`; - a file link or folder link that leads out; - a sibling folder whose name starts like the default; - a missing file; - a cleared chat folder; - a track-named link to a file that isn't audio. - It fails on the old route (200 for the outside file), and the non-audio link case fails without the real-extension check. - `--filter security` (34/34), `--filter music-dj`, `--filter local-music` and `--filter game-assets`: pass. Still to verify by hand: - Manually verify that Music DJ in Custom mode, with a default folder on this device, still plays in the floating player. - Manually verify that a chat folder and a character folder (Chat Settings → Music DJ → Apply to) each play their tracks. - Manually verify that a default folder that is a symlink, or on another disk, still plays. - Manually verify on Windows that a folder typed in a different letter case still plays. ## Docs and release impact - [x] No docs changes needed 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi changed title from [PR #8936] fix(server): play local music files only from the Music DJ folders to [PR #8936] [MERGED] fix(server): play local music files only from the Music DJ folders 2026-11-07 21:50: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#8896
No description provided.