[GH-ISSUE #3056] [Issue]: Bundled "native" game assets can be deleted or moved via bulk and single-file routes, bypassing the protection enforced on folder-delete and single-move #1624

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/3056

Originally assigned to: @SpicyMarinara on GitHub.

What's wrong

Default bundled game assets (music, sprites, backgrounds shipped with the app) are protected from destructive edits by .native marker files. The folder-DELETE route checks containsNativeMarker and the single /move route checks isInsideNativeFolder, both returning 403. But /delete-bulk, single DELETE /file/*, and /move-bulk perform NO native-marker check. A user can therefore permanently delete or relocate the protected bundled assets just by routing the request through delete-bulk / file-delete / move-bulk instead of folder-delete or single-move. Because the only file-level delete routes both skip the check, the protection is effectively meaningless for individual files. The client UI never marks file nodes as native, so the server guard is the only protection.

How to reproduce (try it yourself)

  1. Fresh install seeds bundled assets, e.g. music/exploration/fantasy/calm/<bundled>.mp3, under a directory carrying a .native marker.
  2. POST /api/game-assets/delete-bulk with body { "paths": ["music/exploration/fantasy/calm/<bundled>.mp3"] }.

You'll see: the file passes isSafePath + assertInsideDir + isFile, then unlinkSync(full) deletes the bundled asset and it is reported in succeeded (200). POST /api/game-assets/move-bulk likewise relocates a native asset.

Expected: 403 / a failed entry, matching the folder-DELETE ("Cannot delete folders containing native assets") and single /move ("Cannot move native assets") routes.

Where it is

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

  • /delete-bulk loop lines 1106-1129 — validates path safety + isFile(), then unlinkSync(full), no native check.
  • single DELETE /file/* lines 691-708 — isSafePath -> existsSync -> unlinkSync, no native check.
  • /move-bulk loop lines 1012-1037 — same validation then renameSync(oldFull, newFull), no native check.
  • Contrast guards: folder DELETE lines 832-834 (containsNativeMarker), single /move lines 927-929 (isInsideNativeFolder).

Native-marker seeding: packages/server/src/db/seed-game-assets.ts:75-92,115.

What's happening

The .native-marker protection was added to the folder-DELETE and single-/move handlers but never to the bulk handlers or the single file-DELETE handler. The bulk loops validate path safety and isFile() but never consult the native marker before unlinkSync/renameSync. All routes share prefix /api/game-assets with no route-level auth, so any client that can reach the guarded routes can reach the unguarded ones.

Suggested fix

Add the existing isInsideNativeFolder guard (file-level walk-up check — NOT the folder-level containsNativeMarker, which would throw on a file path) to the three unprotected sites, mirroring single /move (line 927) and each loop's existing failure convention:

  1. Single DELETE /file/* (after the existsSync check at line 700, before unlinkSync at 702):
if (isInsideNativeFolder(filePath)) {
  return reply.status(403).send({ error: "Cannot delete native assets" });
}
  1. /delete-bulk loop (after the isFile check, before unlinkSync(full) at 1127):
if (isInsideNativeFolder(full)) {
  failed.push({ path: filePath, error: "Cannot delete native assets" });
  continue;
}
  1. /move-bulk loop (after the isFile check, before renameSync at 1035):
if (isInsideNativeFolder(oldFull)) {
  failed.push({ path: filePath, error: "Cannot move native assets" });
  continue;
}

Place each guard AFTER the existing existsSync/isFile checks so the internal statSync never runs on a missing path. Do NOT add the guard to /copy or /copy-bulk — copying does not remove or relocate the protected originals. The bulk loops already surface failed entries as a toast, so no client changes are needed.


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/3056 Originally assigned to: @SpicyMarinara on GitHub. **What's wrong** Default bundled game assets (music, sprites, backgrounds shipped with the app) are protected from destructive edits by `.native` marker files. The folder-DELETE route checks `containsNativeMarker` and the single `/move` route checks `isInsideNativeFolder`, both returning 403. But `/delete-bulk`, single `DELETE /file/*`, and `/move-bulk` perform NO native-marker check. A user can therefore permanently delete or relocate the protected bundled assets just by routing the request through delete-bulk / file-delete / move-bulk instead of folder-delete or single-move. Because the only file-level delete routes both skip the check, the protection is effectively meaningless for individual files. The client UI never marks file nodes as native, so the server guard is the only protection. **How to reproduce (try it yourself)** 1. Fresh install seeds bundled assets, e.g. `music/exploration/fantasy/calm/<bundled>.mp3`, under a directory carrying a `.native` marker. 2. `POST /api/game-assets/delete-bulk` with body `{ "paths": ["music/exploration/fantasy/calm/<bundled>.mp3"] }`. You'll see: the file passes `isSafePath` + `assertInsideDir` + `isFile`, then `unlinkSync(full)` deletes the bundled asset and it is reported in `succeeded` (200). `POST /api/game-assets/move-bulk` likewise relocates a native asset. Expected: 403 / a `failed` entry, matching the folder-DELETE ("Cannot delete folders containing native assets") and single `/move` ("Cannot move native assets") routes. **Where it is** `packages/server/src/routes/game-assets.routes.ts`: - `/delete-bulk` loop lines 1106-1129 — validates path safety + `isFile()`, then `unlinkSync(full)`, no native check. - single `DELETE /file/*` lines 691-708 — `isSafePath` -> `existsSync` -> `unlinkSync`, no native check. - `/move-bulk` loop lines 1012-1037 — same validation then `renameSync(oldFull, newFull)`, no native check. - Contrast guards: folder DELETE lines 832-834 (`containsNativeMarker`), single `/move` lines 927-929 (`isInsideNativeFolder`). Native-marker seeding: `packages/server/src/db/seed-game-assets.ts:75-92,115`. **What's happening** The `.native`-marker protection was added to the folder-DELETE and single-`/move` handlers but never to the bulk handlers or the single file-DELETE handler. The bulk loops validate path safety and `isFile()` but never consult the native marker before `unlinkSync`/`renameSync`. All routes share prefix `/api/game-assets` with no route-level auth, so any client that can reach the guarded routes can reach the unguarded ones. **Suggested fix** Add the existing `isInsideNativeFolder` guard (file-level walk-up check — NOT the folder-level `containsNativeMarker`, which would throw on a file path) to the three unprotected sites, mirroring single `/move` (line 927) and each loop's existing failure convention: 1. Single `DELETE /file/*` (after the `existsSync` check at line 700, before `unlinkSync` at 702): ```ts if (isInsideNativeFolder(filePath)) { return reply.status(403).send({ error: "Cannot delete native assets" }); } ``` 2. `/delete-bulk` loop (after the `isFile` check, before `unlinkSync(full)` at 1127): ```ts if (isInsideNativeFolder(full)) { failed.push({ path: filePath, error: "Cannot delete native assets" }); continue; } ``` 3. `/move-bulk` loop (after the `isFile` check, before `renameSync` at 1035): ```ts if (isInsideNativeFolder(oldFull)) { failed.push({ path: filePath, error: "Cannot move native assets" }); continue; } ``` Place each guard AFTER the existing `existsSync`/`isFile` checks so the internal `statSync` never runs on a missing path. Do NOT add the guard to `/copy` or `/copy-bulk` — copying does not remove or relocate the protected originals. The bulk loops already surface `failed` entries as a toast, so no client changes are needed. --- *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:4835428768 --> @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:4835578167 --> @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#1624
No description provided.