[GH-ISSUE #2480] [Issue]: AssetService::rename omits the .. path-containment guard its sibling write paths enforce #1223

Closed
opened 2026-10-21 05:29:16 +07:00 by bsakaguchi · 1 comment
Owner

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

Originally assigned to: @SpicyMarinara on GitHub.

Summary

Severity: Low — security (path-containment) regression. AssetService::rename validates new_name only against /, \, and emptiness — it never rejects .. and never re-runs the joined target through assert_inside_dir, so it drops the path-containment guard its sibling write paths (and main) enforce.

Expected behavior

Mirror main's two-layer guard: reject any new_name whose components include .. (or \/leading slash), run it through sanitize_filename, then re-assert the joined target with assert_inside_dir.

Actual behavior

// src-tauri/crates/assets/src/lib.rs:190-201 (rename)
if new_name.contains('/') || new_name.contains('\\') || new_name.trim().is_empty() {
    return Err(AppError::invalid_input("Invalid asset name"));   // 191 — does NOT reject ".."
}
let source = self.absolute_path(path)?;
let target = source.parent()?.join(new_name);   // 195-198
fs::rename(&source, &target)?;                   // 199 — joined target never re-validated

A new_name of .. (no slash) passes the check, and parent.join("..") resolves outside the managed root. This is the lone outlier: sanitize_filename (:711) explicitly rejects ./.. for uploads, and absolute_path (:55) / write_upload (:265) both gate joined paths through assert_inside_dir; rename does neither.

Steps to reproduce

  1. Invoke the game_assets_rename command (forwards path + new_name verbatim) with path = "music/theme.mp3", new_name = "..".
  2. The pre-check passes; the joined target escapes the asset category folder. (In practice fs::rename onto an existing ancestor dir errors, so the escape currently fails — but the containment guard is missing.)

Impact area

  • Game mode
  • Tauri/Rust storage, assets, LLM, integrations, security, imports, or HTTP runtime

Environment

  • Branch or commit: refactor @ 1fae2c42
  • Run mode: Tauri desktop / remote runtime
  • OS + version: found via static source audit (not runtime-reproduced)
  • Node + pnpm versions: n/a (static audit)
  • Rust version, if relevant: n/a (static audit)
  • Remote Runtime URL configured? not relevant
  • Provider, model, or integration, if relevant: game assets

Logs, screenshots, or video

Static trace: crates/assets/src/lib.rs:190-201 (rename), contrast sanitize_filename:711, absolute_path:55, write_upload:265 (all assert containment).

Regression notes

Regression vs main. packages/server/src/routes/game-assets.routes.ts POST /rename guards newName with isSafePath() (!segment.includes("..")) and re-asserts assertInsideDir(GAME_ASSETS_DIR, join(dir, sanitizeAssetFilename(newName))). The refactor's rewrite dropped both.

Additional context

The actual sandbox escape currently fails because fs::rename onto an existing non-empty ancestor dir errors on every platform, so this is a defense-in-depth/parity gap rather than a live exploit — hence Low. Fix: reject components containing .., run new_name through sanitize_filename, then assert_inside_dir(&self.root, &target) before fs::rename, matching the sibling write paths.

Template check

Please uncheck 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 @Romuromylus on GitHub (Jun 6, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2480 Originally assigned to: @SpicyMarinara on GitHub. ## Summary **Severity: Low — security (path-containment) regression.** `AssetService::rename` validates `new_name` only against `/`, `\`, and emptiness — it never rejects `..` and never re-runs the joined target through `assert_inside_dir`, so it drops the path-containment guard its sibling write paths (and main) enforce. ## Expected behavior Mirror main's two-layer guard: reject any `new_name` whose components include `..` (or `\`/leading slash), run it through `sanitize_filename`, then re-assert the joined target with `assert_inside_dir`. ## Actual behavior ```rust // src-tauri/crates/assets/src/lib.rs:190-201 (rename) if new_name.contains('/') || new_name.contains('\\') || new_name.trim().is_empty() { return Err(AppError::invalid_input("Invalid asset name")); // 191 — does NOT reject ".." } let source = self.absolute_path(path)?; let target = source.parent()?.join(new_name); // 195-198 fs::rename(&source, &target)?; // 199 — joined target never re-validated ``` A `new_name` of `..` (no slash) passes the check, and `parent.join("..")` resolves outside the managed root. This is the lone outlier: `sanitize_filename` (`:711`) explicitly rejects `.`/`..` for uploads, and `absolute_path` (`:55`) / `write_upload` (`:265`) both gate joined paths through `assert_inside_dir`; `rename` does neither. ## Steps to reproduce 1. Invoke the `game_assets_rename` command (forwards `path` + `new_name` verbatim) with `path = "music/theme.mp3"`, `new_name = ".."`. 2. The pre-check passes; the joined target escapes the asset category folder. (In practice `fs::rename` onto an existing ancestor dir errors, so the escape currently fails — but the containment guard is missing.) ## Impact area - [x] Game mode - [x] Tauri/Rust storage, assets, LLM, integrations, security, imports, or HTTP runtime ## Environment - Branch or commit: refactor @ 1fae2c42 - Run mode: Tauri desktop / remote runtime - OS + version: found via static source audit (not runtime-reproduced) - Node + pnpm versions: n/a (static audit) - Rust version, if relevant: n/a (static audit) - Remote Runtime URL configured? not relevant - Provider, model, or integration, if relevant: game assets ## Logs, screenshots, or video Static trace: `crates/assets/src/lib.rs:190-201` (rename), contrast `sanitize_filename:711`, `absolute_path:55`, `write_upload:265` (all assert containment). ## Regression notes Regression vs main. `packages/server/src/routes/game-assets.routes.ts` POST `/rename` guards `newName` with `isSafePath()` (`!segment.includes("..")`) **and** re-asserts `assertInsideDir(GAME_ASSETS_DIR, join(dir, sanitizeAssetFilename(newName)))`. The refactor's rewrite dropped both. ## Additional context The actual sandbox escape currently fails because `fs::rename` onto an existing non-empty ancestor dir errors on every platform, so this is a defense-in-depth/parity gap rather than a live exploit — hence Low. Fix: reject components containing `..`, run `new_name` through `sanitize_filename`, then `assert_inside_dir(&self.root, &target)` before `fs::rename`, matching the sibling write paths. ## Template check Please uncheck 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:29:16 +07:00
Author
Owner

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

Fixed on refactor in 038b7220.

AssetService::rename now sanitizes the requested destination name and validates the target path remains inside the asset root before renaming.

Verification: pnpm typecheck; pnpm build; pnpm check:architecture; cargo check --manifest-path src-tauri/Cargo.toml --workspace; focused Rust backup/profile tests; git diff --check; no .test.ts/.test.tsx files present.

<!-- gh-comment-id:4638718846 --> @SpicyMarinara commented on GitHub (Jun 6, 2026): Fixed on refactor in 038b7220. AssetService::rename now sanitizes the requested destination name and validates the target path remains inside the asset root before renaming. Verification: pnpm typecheck; pnpm build; pnpm check:architecture; cargo check --manifest-path src-tauri/Cargo.toml --workspace; focused Rust backup/profile tests; git diff --check; no .test.ts/.test.tsx files present.
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#1223
No description provided.