fix: keep export files off the public /uploads path #53
No reviewers
Labels
No labels
bug
critical
ebook-branch
high
low
main
medium
release-blocker
security
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
jfro/fuzzy_catalog!53
Loading…
Reference in a new issue
No description provided.
Delete branch "jtk/private-exports"
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?
Export files land in
UPLOAD_PATH/exports, andendpoint.exserves all ofUPLOAD_PATHat/uploadsthroughPlug.Staticwith no auth, so anyone who guessed an export's file name could download it.Change
FuzzyCatalogWeb.Plugs.BlockPrivateUploads, plugged in the endpoint just before the/uploadsstatic plug. Anything under/uploads/exports/gets a 404 and the request is halted.Plug.Staticdoes, so/uploads/%65xports/...is blocked too.ImportExportController, which reads the file from disk, so nothing that's meant to work changes.I went with blocking the path rather than moving exports out of
UPLOAD_PATH. Moving them would break theexports/...paths already stored on existing jobs and thejob_file_path/1root check, and the issue lists either fix as fine.Tests
/exportspath.mix precommitpasses: 542 tests, 0 failures.Fixes #35
13a38c7deb81b808be1fReview from Nye (changes requested)
PR #53, fix: keep export files off the public /uploads path (
13a38c7). Static review against Plug 1.20.3's Plug.Static source; I didn't run the suite here.dir |> URI.decode() |> String.downcase() |> String.trim_trailing(". "). Add tests for "EXPORTS", "%45xports" and "exports.".Checked and OK:
Review from Nye (approved) — re-review at
01f226eThe blocker is fixed: the segment is URI-decoded, downcased and stripped of trailing dots/spaces; malformed %-encoding falls through to Plug.Static's 400. New endpoint tests for HEAD, the bare dir and dot segments are good.
String.downcasedoesn't fold U+017F LONG S. Unicode case folding maps ſ → s (CaseFolding.txt017F; C; 0073), which case-insensitive filesystems using Unicode folding (APFS) can apply, so/uploads/export%C5%BF/<file>may still resolve. Use:string.casefold/1instead ofString.downcase/1innormalize/1and add"/uploads/export%C5%BF/x.json"to the variants list.URI.parse, and//uploads//exports/xparsesuploadsas the HOST, so path_info is["exports", x]and the 404 comes from the router, not the plug. Use"/uploads//exports/#{name}"(single leading slash).Review from Nye (approved) — re-review at
60356d6I re-reviewed
60356d6: both follow-ups are done. normalize uses :string.casefold, and the test for export%C5%BF passes. The doubled-slash test now really exercises /uploads//exports/…. I checked in Elixir 1.18 that :string.casefold raises ArgumentError on invalid UTF-8 (%FF), and the existing rescue returns the raw segment, so it can't become a 500 or a bypass. No further changes.