[GH-ISSUE #5099] [Bug]: Gallery conversation selfies return 404 on Windows after v2.4.2 #2821

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

Originally created by @SpicyMarinara on GitHub (Aug 15, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/5099

Originally assigned to: @SpicyMarinara on GitHub.

Summary

Gallery images, especially Conversation selfies, fail to display with HTTP 404 on Windows after updating to Marinara Engine v2.4.2. The files remain valid and exist on disk, and the Gallery listing endpoint still returns their metadata and prompts. Connection-profile test images continue to work.

Affected environment

  • Marinara Engine: v2.4.2
  • Platform: Windows
  • Launch path: start.bat → npm start → node packages/server/dist/index.js

Observed behavior

  • Gallery listing succeeds and includes the affected image records and prompts.
  • Requests to /api/gallery/file/:chatId/:filename return 404.
  • The referenced image files exist on disk and can be opened normally.
  • Connection-profile test images display successfully.

Expected behavior

Valid Gallery files contained within the configured Gallery directory should be served successfully on Windows while traversal and symlink escapes remain rejected.

Root-cause analysis

The Gallery route resolves and constrains the stored path through resolveStoredGalleryFile(image.filePath, GALLERY_DIR), which uses assertInsideDir. It then performs a second gate through validateImageAssetFile.

validateImageAssetFile calls resolveAllowedMediaPath in packages/server/src/utils/media-file-security.ts. That helper uses fs.realpath() for both the requested file and each configured root, then relies on a case-sensitive string-prefix comparison. On Windows, canonical paths may differ because of drive-letter casing, junctions, or redirected/OneDrive paths. A valid Gallery file can therefore fail the prefix check, return null, and be surfaced as 404.

Connection-profile test images bypass this validation path, explaining why they remain unaffected.

Temporary local workaround

The reporter patched packages/server/dist/routes/gallery.routes.js and replaced the validateImageAssetFile / sendValidatedMediaFile call with direct file reading and a content type derived from the extension. That restored Gallery images for npm start because it runs the compiled dist output.

This compiled-output patch is diagnostic only and should not be adopted directly upstream: it will be lost on rebuild and bypasses the shared media validation and streaming behavior.

Suggested upstream direction

Fix the TypeScript source and retain defense in depth. Prefer making resolveAllowedMediaPath compare canonical Windows paths correctly, including case-insensitive drive/path comparison where appropriate, while continuing to reject files outside all allowed roots. The Gallery route can also pass GALLERY_DIR explicitly as additionalRoot if needed, but that alone may not address canonicalization mismatches.

Acceptance criteria

  • Valid Conversation selfies and other Gallery images are served on Windows when their files exist under GALLERY_DIR.
  • Drive-letter casing, junctions, and redirected/OneDrive path canonicalization do not create false 404 responses.
  • Traversal and symlink escapes remain rejected.
  • Image signature/MIME validation and existing response streaming behavior remain intact.
  • The fix is made in TypeScript source and survives a normal rebuild used by start.bat.
  • Regression coverage exercises Windows-style case-insensitive containment behavior.
Originally created by @SpicyMarinara on GitHub (Aug 15, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/5099 Originally assigned to: @SpicyMarinara on GitHub. ## Summary Gallery images, especially Conversation selfies, fail to display with HTTP 404 on Windows after updating to Marinara Engine v2.4.2. The files remain valid and exist on disk, and the Gallery listing endpoint still returns their metadata and prompts. Connection-profile test images continue to work. ## Affected environment - Marinara Engine: v2.4.2 - Platform: Windows - Launch path: `start.bat` → `npm start` → `node packages/server/dist/index.js` ## Observed behavior - Gallery listing succeeds and includes the affected image records and prompts. - Requests to `/api/gallery/file/:chatId/:filename` return 404. - The referenced image files exist on disk and can be opened normally. - Connection-profile test images display successfully. ## Expected behavior Valid Gallery files contained within the configured Gallery directory should be served successfully on Windows while traversal and symlink escapes remain rejected. ## Root-cause analysis The Gallery route resolves and constrains the stored path through `resolveStoredGalleryFile(image.filePath, GALLERY_DIR)`, which uses `assertInsideDir`. It then performs a second gate through `validateImageAssetFile`. `validateImageAssetFile` calls `resolveAllowedMediaPath` in `packages/server/src/utils/media-file-security.ts`. That helper uses `fs.realpath()` for both the requested file and each configured root, then relies on a case-sensitive string-prefix comparison. On Windows, canonical paths may differ because of drive-letter casing, junctions, or redirected/OneDrive paths. A valid Gallery file can therefore fail the prefix check, return `null`, and be surfaced as 404. Connection-profile test images bypass this validation path, explaining why they remain unaffected. ## Temporary local workaround The reporter patched `packages/server/dist/routes/gallery.routes.js` and replaced the `validateImageAssetFile` / `sendValidatedMediaFile` call with direct file reading and a content type derived from the extension. That restored Gallery images for `npm start` because it runs the compiled `dist` output. This compiled-output patch is diagnostic only and should not be adopted directly upstream: it will be lost on rebuild and bypasses the shared media validation and streaming behavior. ## Suggested upstream direction Fix the TypeScript source and retain defense in depth. Prefer making `resolveAllowedMediaPath` compare canonical Windows paths correctly, including case-insensitive drive/path comparison where appropriate, while continuing to reject files outside all allowed roots. The Gallery route can also pass `GALLERY_DIR` explicitly as `additionalRoot` if needed, but that alone may not address canonicalization mismatches. ## Acceptance criteria - Valid Conversation selfies and other Gallery images are served on Windows when their files exist under `GALLERY_DIR`. - Drive-letter casing, junctions, and redirected/OneDrive path canonicalization do not create false 404 responses. - Traversal and symlink escapes remain rejected. - Image signature/MIME validation and existing response streaming behavior remain intact. - The fix is made in TypeScript source and survives a normal rebuild used by `start.bat`. - Regression coverage exercises Windows-style case-insensitive containment behavior.
Author
Owner

@SpicyMarinara commented on GitHub (Aug 15, 2026):

SpicyMarinara is taking this in fix/5099-windows-gallery-paths; a draft PR will be linked as soon as the regression fix is committed.

<!-- gh-comment-id:5304588066 --> @SpicyMarinara commented on GitHub (Aug 15, 2026): SpicyMarinara is taking this in `fix/5099-windows-gallery-paths`; a draft PR will be linked as soon as the regression fix is committed.
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#2821
No description provided.