fix: stop book params from setting cover_image_key and confine storage keys #20
Loading…
Reference in a new issue
No description provided.
Delete branch "jtk/cover-key-traversal"
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?
Fixes #7 (high):
cover_image_keywas cast from book params, so a user could setbook[cover_image_key]=../../../<file>on create/update, then delete the book or sendremove_cover=true, andLocalBackend.delete/1wouldFile.rmthat path (the same key also fedexists?/retrieve_url).Independent of #18/#19 (branched from main).
Changes
cover_image_keyis dropped from request params (create, update, add-from-lookup, scan, batch add) and logged at warning if sent. Only the server sets it after storing an upload or download.cover_image_keymust look likecovers/<uuid>.(jpg|png|gif|webp), the only shapeStorage.store_coverproduces. Internal callers (sync, the ebook worker) keep working; existing rows aren't revalidated.Path.safe_relative/1; absolute keys, empty/nil keys and any..that leavesbase_pathreturn{:error, :invalid_key}(orfalsefromexists?) and log a warning, instead of touching the filesystem. Pages with a bad stored key show no cover rather than crashing.Tests
test/fuzzy_catalog/storage/local_backend_test.exs(traversal, absolute, empty and nil keys refused for store/delete/exists?/retrieve_url; a file outside uploads survives),test/fuzzy_catalog/catalog/book_test.exs(key format), and controller tests that send a traversal key on create and update.mix precommit: 167 tests pass.Review by Nye (PR review / audit) — APPROVE @
5727a04(originally @7240fdf)Closes #7: controller drops
cover_image_keyfrom params on create/update and add-from-lookup;Book.changesetvalidate_formatonly acceptscovers/<uuid>.(jpg|png|gif|webp)(validate_* runs only on changes, so legacy rows still save); LocalBackend usesPath.safe_relativefor store/delete/exists?. Every server path that writes keys (store_cover, download_and_store_cover, upload, sync, #17's ebook thumbnails) produces exactly that format, so no regressions. Tests cover changeset, backend and controller. Re-checked after main was merged in: the lib/ diff is identical to7240fdf, #19's test is kept, CI green.Merge note: will conflict with #17 in book.ex: keep both (#17's rating validation and this PR's cover_image_key handling).