mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[PR #2533] [MERGED] fix(gallery): block path traversal in upload/delete handlers #5636
Labels
No labels
android
bug
bugfix
ci
client
code freeze pause
container
dependencies
docs
documentation
duplicate
enhancement
feature
feature
feature
feature-creep
fixed-in-refactor
fixed-in-staging
good first issue
help wanted
in-pr
in-pr
needs-codeowner-decision
normal-scope
old-codebase
old-codebase
pull-request
qol
question
refactor
regression
revisit later
roadmap
scope-risk
scope-risk
server
server
shared
soup
upstream
windows
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Pasta-Devs/Marinara-Engine#5636
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/2533
Author: @Romuromylus
Created: 6/9/2026
Status: ✅ Merged
Merged: 6/9/2026
Merged by: @SpicyMarinara
Base:
staging← Head:fix/gallery-path-traversal📝 Commits (2)
614fbc2fix(gallery): block path traversal in upload/delete via chatId guard + assertInsideDir9445fa4Merge branch 'staging' into fix/gallery-path-traversal📊 Changes
1 file changed (+32 additions, -5 deletions)
View changed files
📝
packages/server/src/routes/gallery.routes.ts(+32 -5)📄 Description
Linked issue
Closes #2524
Why this change
The chat-gallery upload and delete handlers built on-disk paths from request-controlled input with no traversal sanitization and no
assertInsideDirbackstop — unlike the sibling avatars/game-assets routes.req.params.chatIdstraight into the write path. Fastify percent-decodes the param, soPOST /api/gallery/%2e%2e%2f%2e%2e%2fevil/uploadyieldschatId = "../../evil"and writes attacker bytes outsideGALLERY_DIR.join(GALLERY_DIR, image.filePath), wherefilePathwas persisted from the same unsanitizedchatIdat upload time — so a poisoned row could unlink a file outside the gallery root.What changed
packages/server/src/routes/gallery.routes.ts:isValidChatId()(rejects..,/,\, empty, and NUL byte) and check it at the top of the upload handler, beforeensureDirrunsmkdirSync— so a traversalchatIdnever creates a directory outside the root.assertInsideDir(GALLERY_DIR, ...)as defense-in-depth (400 on escape).assertInsideDir(GALLERY_DIR, ...); on escape it logs an err-first Pino warn and still falls through tostorage.remove(id)so a poisoned/orphan row is cleaned up rather than left undeletable.Mirrors
avatars.routes.ts(isValidFilename) andgame-assets.routes.ts(assertInsideDir). The serve route already guardedchatIdbut omitted backslash; the new helper includes it.Not a regression: both handlers are byte-identical on
main; long-standing shared bug.Validation
pnpm checkpasses locallyCONTRIBUTING.mdManual verification notes
pnpm checkpasses locally. Added a local-only node:test (gallery-path-traversal.test.ts, gitignored):isValidChatIdrejects traversal/separators/empty/NUL and accepts legitimate nanoids (negative control), andassertInsideDirreturns the resolved path for an in-root target (negative control) and throws on an escaping/poisonedfilePath. Local run: 4/4 pass.Still to verify manually against the deploy:
/api/gallery/%2e%2e%2f%2e%2e%2fevil/upload) now returns 400Invalid chatId.chatIdstill succeeds and the image appears in that chat's gallery (happy path unaffected).Docs and release impact
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.