Conversation
UploadPostAttachment stores an upload with a lowercased extension (Report.PDF is saved as files/post/<hash>.pdf) but keeps the original name in the download link. The download route rebuilt the local name from the link's extension as typed, so on a case-sensitive filesystem it looked for <hash>.PDF, did not find it, and redirected to /404. Lowercase the extension when resolving the local path. Generated-by: Claude Opus 5.5 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
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.
Fixes: n/a (no existing issue; details below)
Proposed Changes
Report.PDForScan.ZIPand the post shows a link, but clicking it redirects to/404. Files from Windows, scanners and cameras often have uppercase extensions like this.UploadPostAttachmentlowercases the extension when it saves the file (fileExt := strings.ToLower(path.Ext(...)), so the file becomesfiles/post/<hash>.pdf), but it puts the original name in the link (/uploads/files/post/<hash>/Report.PDF). The download route ininternal/router/static_router.gorebuilt the local name from the link's extension without lowercasing it, so it looked for<hash>.PDF. That file doesn't exist, soCheckFileExistfailed and the route redirected to/404. On macOS/Windows default filesystems the lookup is case-insensitive, which hides the bug in local development.attachmentFileLocalPathnow lowercases the extension, matching what the uploader stores. The download filename sent inContent-Dispositionstill uses the originalReport.PDF, and the path traversal checks are unchanged.internal/router/static_router_test.go):TestAttachmentFileLocalPathLowercasesExtensionchecks that/hash/Report.PDFresolves tofiles/post/hash.pdf. This check doesn't depend on the filesystem.TestAttachmentDownloadWithUppercaseExtensionregisters the real static router on a gin engine, storeshash.pdfthe way the uploader does, and requests/uploads/files/post/hash/Report.PDF.dev@6c00c788, running on a case-sensitive volume, both fail: the path is.../hash.PDFand the response is302 Location: /404. With the fix, all router tests pass. The existing traversal test is unchanged and still passes.go test ./internal/router/,go vet,gofmt, andgolangci-lintv2.6.2 (the repo's.golangci.yaml) report 0 issues.This bug was found and the fix and tests were written with AI assistance (Claude); I reviewed the change and ran the tests above.