fix: prevent upload path traversal (C3)#337
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
C3 — sista CRITICAL i Sprint 3-A.
Hardenar
/api/upload-routen mot path traversal:image/jpeg → jpg,image/png → png,image/webp → webp,application/pdf → pdf(fallbackbin) — INTE frånfile.name.split(".").pop(). Tidigare kundefile.name = "evil.png/../../../etc/passwd"placera filer utanför bucket-namespace.assertSafeStorageFileName()isupabase-storage.ts(blockerar/,\\,..,\x00, leading dot, tom, >255 chars). Anropas iuploadFile()och iuploadMessageAttachment()(mot leaf, så bucket-segmentet inte påverkas).z.string().uuid()påentityId— fail-fast 400 "Ogiltigt entityId" innan ownership-check, defense-in-depth innan interpolation i path.Test plan
assertSafeStorageFileName(H1-H6)upload/route.test.ts(T1-T5: traversal i file.name, null-byte, MIME-baserad ext, traversal i entityId, non-UUID entityId)native/provider/upload,messages/attachmentsnpm run check:all4/4 gröna (typecheck, test:run, lint, check:swedish)Out of scope
bookingIdimessages/attachments/route.ts(skyddat indirekt avloadBookingForMessaging)Upload.originalName(ej path-använt; XSS-vektor om framtida vy renderar otrust)deleteFile/createMessageSignedUrlmot ovaliderad path (idag bara DB-källad)Sprint 3-A status efter merge
CRITICAL: C4 ✅ • C1 ✅ • C2 ✅ • C3 ✅ — alla 4 åtgärdade.