[GH-ISSUE #5108] [Issue]: Gallery images return 404 on Windows after v2.4.2 update #2823

Closed
opened 2026-10-21 05:56:17 +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/5108

Summary

Conversation gallery images fail to display after updating to v2.4.2 because the gallery file-serving route returns HTTP 404. Connection profile test images continue to work, and the gallery listing endpoint still displays prompts.

Expected behavior

Valid conversation gallery images should be served and displayed.

Actual behavior

Gallery image requests return HTTP 404, even though the files are valid and exist on disk. Connection profile test images are unaffected.

Steps to reproduce

  1. Update Marinara Engine to v2.4.2.
  2. Open a conversation gallery containing selfie images.
  3. Request or view a gallery image and observe that the file-serving route returns HTTP 404.

Environment

  • Marinara Engine version: 2.4.2
  • Install type: Not provided
  • OS + version: Windows; exact version not provided
  • Browser or app shell: Not provided

Logs, screenshots, or video

HTTP 404 responses from the gallery file-serving route. No screenshots or video provided.

Additional context

The gallery listing endpoint works and shows prompts. The files exist on disk. validateImageAssetFile in packages/server/src/utils/media-file-security.ts calls resolveAllowedMediaPath, which uses fs.realpath() and can fail its path-prefix check on Windows due to drive-letter casing, junctions, or OneDrive redirects. Connection test images bypass this validation. A workaround was applied to packages/server/dist/routes/gallery.routes.js by directly serving the already-sanitized path with readFileSync and a content type based on the file extension. The TypeScript source should also be patched so the fix survives rebuilds. Potential upstream fixes include handling Windows realpath normalization, passing GALLERY_DIR as an additional root, or removing the redundant validation from the gallery route.

Discord message: Discord message from ₍ᐢ..ᐢ₎ 𝚗 𝚊 𝚝 𝚝 𝚘 – ♡
Discord message link: https://discord.com/channels/1417099416812392641/1537975955212083250/1538295003997274122
Requested by: kolache (k0lache, Discord ID 220320261780668416)

Discord message transcript (1 message)
[2026-08-15T21:15:09.092Z] ₍ᐢ..ᐢ₎ 𝚗 𝚊 𝚝 𝚝 𝚘 – ♡: > Here's the TL;DR for the dev team:
> 
> Bug: Gallery images (conversation selfies) fail to display with HTTP 404 after updating to v2.4.2. Connection profile test images work fine. Files are valid and exist on disk. Gallery listing endpoint works (shows prompts) but file-serving route returns 404.
> 
> Root cause: validateImageAssetFile in packages/server/src/utils/media-file-security.ts rejects valid gallery files. The function calls resolveAllowedMediaPath, which uses fs.realpath() to canonicalize both the file path and configured root paths, then checks if the file path starts with a root prefix. On Windows, realpath can canonicalize paths differently (drive letter casing, junction points, OneDrive redirects), causing the prefix check to fail → returns null → 404. Connection test images bypass validateImageAssetFile entirely, which is why they work.
> 
> Fix applied (to packages/server/dist/routes/gallery.routes.js, compiled output): Replaced the validateImageAssetFile + sendValidatedMediaFile call in the /file/:chatId/:filename route handler with a direct file serve — readFileSync + reply.send with a content-type lookup from the file extension. The path is already sanitized by resolveStoredGalleryFile + assertInsideDir earlier in the handler, so the validateImageAssetFile gate was redundant.
> 
> Suggested upstream fix: Either fix resolveAllowedMediaPath to handle Windows realpath canonicalization differences (e.g. normalize drive letter casing before prefix comparison), or pass GALLERY_DIR as additionalRoot to validateImageAssetFile, or remove the redundant validation from the gallery file-serving route since path safety is already handled.
> 
> Note: The fix was applied to compiled JS (dist/) because the user runs via start.bat → npm start → node packages/server/dist/index.js. The TypeScript source should also be patched so the fix survives rebuilds.
> 
> That's the whole saga in one page, kek. Feel free to copy-paste that to the devs.
[Discord message: https://discord.com/channels/1417099416812392641/1537975955212083250/1538295003997274122]

Template check

Please uncheck (untick) 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 @SpicyMarinara on GitHub (Aug 15, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/5108 ## Summary Conversation gallery images fail to display after updating to v2.4.2 because the gallery file-serving route returns HTTP 404. Connection profile test images continue to work, and the gallery listing endpoint still displays prompts. ## Expected behavior Valid conversation gallery images should be served and displayed. ## Actual behavior Gallery image requests return HTTP 404, even though the files are valid and exist on disk. Connection profile test images are unaffected. ## Steps to reproduce 1. Update Marinara Engine to v2.4.2. 2. Open a conversation gallery containing selfie images. 3. Request or view a gallery image and observe that the file-serving route returns HTTP 404. ## Environment - Marinara Engine version: 2.4.2 - Install type: Not provided - OS + version: Windows; exact version not provided - Browser or app shell: Not provided ## Logs, screenshots, or video HTTP 404 responses from the gallery file-serving route. No screenshots or video provided. ## Additional context The gallery listing endpoint works and shows prompts. The files exist on disk. validateImageAssetFile in packages/server/src/utils/media-file-security.ts calls resolveAllowedMediaPath, which uses fs.realpath() and can fail its path-prefix check on Windows due to drive-letter casing, junctions, or OneDrive redirects. Connection test images bypass this validation. A workaround was applied to packages/server/dist/routes/gallery.routes.js by directly serving the already-sanitized path with readFileSync and a content type based on the file extension. The TypeScript source should also be patched so the fix survives rebuilds. Potential upstream fixes include handling Windows realpath normalization, passing GALLERY_DIR as an additional root, or removing the redundant validation from the gallery route. Discord message: Discord message from ₍ᐢ..ᐢ₎ 𝚗 𝚊 𝚝 𝚝 𝚘 – ♡ Discord message link: https://discord.com/channels/1417099416812392641/1537975955212083250/1538295003997274122 Requested by: kolache (k0lache, Discord ID 220320261780668416) <details> <summary>Discord message transcript (1 message)</summary> ```text [2026-08-15T21:15:09.092Z] ₍ᐢ..ᐢ₎ 𝚗 𝚊 𝚝 𝚝 𝚘 – ♡: > Here's the TL;DR for the dev team: > > Bug: Gallery images (conversation selfies) fail to display with HTTP 404 after updating to v2.4.2. Connection profile test images work fine. Files are valid and exist on disk. Gallery listing endpoint works (shows prompts) but file-serving route returns 404. > > Root cause: validateImageAssetFile in packages/server/src/utils/media-file-security.ts rejects valid gallery files. The function calls resolveAllowedMediaPath, which uses fs.realpath() to canonicalize both the file path and configured root paths, then checks if the file path starts with a root prefix. On Windows, realpath can canonicalize paths differently (drive letter casing, junction points, OneDrive redirects), causing the prefix check to fail → returns null → 404. Connection test images bypass validateImageAssetFile entirely, which is why they work. > > Fix applied (to packages/server/dist/routes/gallery.routes.js, compiled output): Replaced the validateImageAssetFile + sendValidatedMediaFile call in the /file/:chatId/:filename route handler with a direct file serve — readFileSync + reply.send with a content-type lookup from the file extension. The path is already sanitized by resolveStoredGalleryFile + assertInsideDir earlier in the handler, so the validateImageAssetFile gate was redundant. > > Suggested upstream fix: Either fix resolveAllowedMediaPath to handle Windows realpath canonicalization differences (e.g. normalize drive letter casing before prefix comparison), or pass GALLERY_DIR as additionalRoot to validateImageAssetFile, or remove the redundant validation from the gallery file-serving route since path safety is already handled. > > Note: The fix was applied to compiled JS (dist/) because the user runs via start.bat → npm start → node packages/server/dist/index.js. The TypeScript source should also be patched so the fix survives rebuilds. > > That's the whole saga in one page, kek. Feel free to copy-paste that to the devs. [Discord message: https://discord.com/channels/1417099416812392641/1537975955212083250/1538295003997274122] ``` </details> ## Template check Please **uncheck (untick)** 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:56:17 +07:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

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

Prof Mari says:

Here's the TL;DR for the dev team:

Bug: Gallery images (conversation selfies) fail to display with HTTP 404 after updating to v2.4.2. Connection profile test images work fine. Files are valid and exist on disk. Gallery listing endpoint works (shows prompts) but file-serving route returns 404.

Root cause: validateImageAssetFile in packages/server/src/utils/media-file-security.ts rejects valid gallery files. The function calls resolveAllowedMediaPath, which uses fs.realpath() to canonicalize both the file path and configured root paths, then checks if the file path starts with a root prefix. On Windows, realpath can canonicalize paths differently (drive letter casing, junction points, OneDrive redirects), causing the prefix check to fail → returns null → 404. Connection test images bypass validateImageAssetFile entirely, which is why they work.

Fix applied (to packages/server/dist/routes/gallery.routes.js, compiled output): Replaced the validateImageAssetFile + sendValidatedMediaFile call in the /file/:chatId/:filename route handler with a direct file serve — readFileSync + reply.send with a content-type lookup from the file extension. The path is already sanitized by resolveStoredGalleryFile + assertInsideDir earlier in the handler, so the validateImageAssetFile gate was redundant.

Suggested upstream fix: Either fix resolveAllowedMediaPath to handle Windows realpath canonicalization differences (e.g. normalize drive letter casing before prefix comparison), or pass GALLERY_DIR as additionalRoot to validateImageAssetFile, or remove the redundant validation from the gallery file-serving route since path safety is already handled.

Note: The fix was applied to compiled JS (dist/) because the user runs via start.bat → npm start → node packages/server/dist/index.js. The TypeScript source should also be patched so the fix survives rebuilds.

That's the whole saga in one page, kek. Feel free to copy-paste that to the devs.

<!-- gh-comment-id:5304637636 --> @kolacheee commented on GitHub (Aug 15, 2026): Prof Mari says: Here's the TL;DR for the dev team: Bug: Gallery images (conversation selfies) fail to display with HTTP 404 after updating to v2.4.2. Connection profile test images work fine. Files are valid and exist on disk. Gallery listing endpoint works (shows prompts) but file-serving route returns 404. Root cause: validateImageAssetFile in packages/server/src/utils/media-file-security.ts rejects valid gallery files. The function calls resolveAllowedMediaPath, which uses fs.realpath() to canonicalize both the file path and configured root paths, then checks if the file path starts with a root prefix. On Windows, realpath can canonicalize paths differently (drive letter casing, junction points, OneDrive redirects), causing the prefix check to fail → returns null → 404. Connection test images bypass validateImageAssetFile entirely, which is why they work. Fix applied (to packages/server/dist/routes/gallery.routes.js, compiled output): Replaced the validateImageAssetFile + sendValidatedMediaFile call in the /file/:chatId/:filename route handler with a direct file serve — readFileSync + reply.send with a content-type lookup from the file extension. The path is already sanitized by resolveStoredGalleryFile + assertInsideDir earlier in the handler, so the validateImageAssetFile gate was redundant. Suggested upstream fix: Either fix resolveAllowedMediaPath to handle Windows realpath canonicalization differences (e.g. normalize drive letter casing before prefix comparison), or pass GALLERY_DIR as additionalRoot to validateImageAssetFile, or remove the redundant validation from the gallery file-serving route since path safety is already handled. Note: The fix was applied to compiled JS (dist/) because the user runs via start.bat → npm start → node packages/server/dist/index.js. The TypeScript source should also be patched so the fix survives rebuilds. That's the whole saga in one page, kek. Feel free to copy-paste that to the devs.
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#2823
No description provided.