[PR #5107] [MERGED] Fix Windows gallery media containment #6631

Closed
opened 2026-10-23 04:12:15 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/5107
Author: @SpicyMarinara
Created: 8/15/2026
Status: ✅ Merged
Merged: 8/16/2026
Merged by: @SpicyMarinara

Base: staging ← Head: fix/5099-windows-gallery-paths


📝 Commits (1)

  • 9d6579e Fix Windows gallery media containment

📊 Changes

3 files changed (+58 additions, -4 deletions)

View changed files

📝 CHANGELOG.md (+1 -0)
📝 packages/server/src/utils/media-file-security.ts (+17 -3)
📝 scripts/regressions/profile-import-asset-security.regression.ts (+40 -1)

📄 Description

Important

Contributions target staging. Only SpicyMarinara may promote this repository's staging branch or a same-repository hotfix/* branch to main.
Outside and first-time contributors also require an approving review from SpicyMarinara.

Linked issue

Closes #5099

Why this change

Valid Gallery images could return 404 on Windows when realpath canonicalized their drive letter or directory casing differently from the configured media root. The file was safe and present, but the case-sensitive prefix check rejected it.

What changed

  • Replaced string-prefix containment with a platform-aware canonical relative-path check.
  • Made Windows canonical containment case-insensitive while retaining POSIX case sensitivity.
  • Preserved traversal, sibling-prefix, symlink, image-signature, and validated-descriptor protections.
  • Added regression cases for Windows case differences, sibling escapes, different drives, and POSIX case sensitivity.
  • Added the user-facing fix to the Unreleased changelog.

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

Automated verification performed:

  • pnpm --filter @marinara-engine/server lint
  • pnpm --filter @marinara-engine/server exec tsx ../../scripts/regressions/profile-import-asset-security.regression.ts
  • git diff --check

A real Windows install with drive-case, junction, or OneDrive canonicalization remains a maintainer/manual verification item.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed
  • Translated docs on the docs-i18n branch updated to match, or a [docs-i18n] follow-up issue opened
  • Version/release files updated (only if this PR includes a version bump)

No user-facing documentation page or release metadata changed. CHANGELOG.md includes the fix.

UI evidence (if applicable)

Not applicable; this is a server file-serving regression.

Summary by CodeRabbit

  • Bug Fixes

    • Improved media path matching for Windows Gallery locations, including paths with differing letter casing.
    • Strengthened protection against similarly named sibling folders, alternate drives, traversal attempts, and symlink-based escapes.
    • Preserved case-sensitive path behavior on Linux.
  • Documentation

    • Added a changelog entry describing the Windows path-matching improvements.

🔄 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/5107 **Author:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Created:** 8/15/2026 **Status:** ✅ Merged **Merged:** 8/16/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `fix/5099-windows-gallery-paths` --- ### 📝 Commits (1) - [`9d6579e`](https://github.com/Pasta-Devs/Marinara-Engine/commit/9d6579ed1382b2c16d879824f3999d255a6e8024) Fix Windows gallery media containment ### 📊 Changes **3 files changed** (+58 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+1 -0) 📝 `packages/server/src/utils/media-file-security.ts` (+17 -3) 📝 `scripts/regressions/profile-import-asset-security.regression.ts` (+40 -1) </details> ### 📄 Description > [!IMPORTANT] > Contributions target `staging`. Only `SpicyMarinara` may promote this repository's `staging` branch or a same-repository `hotfix/*` branch to `main`. > Outside and first-time contributors also require an approving review from `SpicyMarinara`. ## Linked issue Closes #5099 ## Why this change Valid Gallery images could return 404 on Windows when `realpath` canonicalized their drive letter or directory casing differently from the configured media root. The file was safe and present, but the case-sensitive prefix check rejected it. ## What changed - Replaced string-prefix containment with a platform-aware canonical relative-path check. - Made Windows canonical containment case-insensitive while retaining POSIX case sensitivity. - Preserved traversal, sibling-prefix, symlink, image-signature, and validated-descriptor protections. - Added regression cases for Windows case differences, sibling escapes, different drives, and POSIX case sensitivity. - Added the user-facing fix to the Unreleased changelog. ## 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 Automated verification performed: - `pnpm --filter @marinara-engine/server lint` - `pnpm --filter @marinara-engine/server exec tsx ../../scripts/regressions/profile-import-asset-security.regression.ts` - `git diff --check` A real Windows install with drive-case, junction, or OneDrive canonicalization remains a maintainer/manual verification item. ## Docs and release impact - [ ] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed - [ ] Translated docs on the `docs-i18n` branch updated to match, or a `[docs-i18n]` follow-up issue opened - [ ] Version/release files updated (only if this PR includes a version bump) No user-facing documentation page or release metadata changed. `CHANGELOG.md` includes the fix. ## UI evidence (if applicable) Not applicable; this is a server file-serving regression. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Improved media path matching for Windows Gallery locations, including paths with differing letter casing. * Strengthened protection against similarly named sibling folders, alternate drives, traversal attempts, and symlink-based escapes. * Preserved case-sensitive path behavior on Linux. * **Documentation** * Added a changelog entry describing the Windows path-matching improvements. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-23 04:12:15 +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#6631
No description provided.