Repository navigation
fix(server): keep pantry edits inside /api/pantry - #666
Merged
Merged
Conversation
LeMyst
marked this pull request as ready for review
October 10, 2026 15:18
LeMyst
force-pushed
the
fix/pantry-section-urls
branch
from
October 10, 2026 16:46
5834d39 to
39066e0
Compare
The pantry page put the section name into its edit and remove URLs unencoded, so a section such as `../recipes/Soup.cook#` made an editor's Save overwrite `Soup.cook` and Remove delete a recipe, with the editor's rights. A shopper could add such a section. The page now builds those URLs in one place, encoding both parts, and refuses to send a request for a section or item named `.` or `..`, which the browser resolves as path steps even when encoded. The server refuses new sections that are `.` or `..` or contain `/`, `\`, `#`, `?` or control characters, and item names that are `.` or `..` or contain control characters. Closes cooklang#659 Co-Authored-By: Claude Opus 5.5 <[email protected]>
cooklang#629 added POST /api/pantry/rename after this branch was opened, and it took any new name, so a section could still be renamed to `..` or `../recipes/Soup.cook#`. The rename now applies the rule a new section gets when an item is added: no `.` or `..`, no `/`, `\`, `#`, `?` or control characters, answered with `400`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
LeMyst
force-pushed
the
fix/pantry-section-urls
branch
from
October 10, 2026 17:25
39066e0 to
d554614
Compare
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.
Closes #659
Problem
The pantry page built its edit and remove requests as
/api/pantry/${section}/${encodeURIComponent(name)}, withsectionunencoded. A section named../recipes/Soup.cook#sent an editor's Save toPUT /api/recipes/Soup.cookand Remove toDELETE /api/recipes/…, with the editor's rights. A shopper can create such a section throughPOST /api/pantry/add, and since #629 throughPOST /api/pantry/rename. Apantry.confthat arrives through sync or version control can contain one too.#653 (merged) rewrote the page and now encodes both parts. Encoding does not cover
.and.., though:encodeURIComponentleaves dots alone, and the URL parser resolves%2E%2Eas..too. So a section named..still moves the request out of/api/pantry/, and the server still accepts such sections.Changes
templates/pantry.html(on top of #653's page)pantryItemUrl(section, name), used by Save and Remove, encodes both parts.send()refuses a URL with a.or..segment. The page shows the error banner instead of sending the request.src/server/handlers/pantry.rs: returns400whenPOST /api/pantry/addgets a section that is.or.., or contains/,\,#,?or a control character. A section is a TOML table name, so nothing legitimate needs these.POST /api/pantry/addgets an item name that is.or.., or contains a control character. The page encodes names, sosalt/pepperorMilk #2stay allowed.POST /api/pantry/renamegets a new name that breaks the section rule. Both endpoints shareis_section_segment.PUTandDELETE /api/pantry/{section}/{name}stay as they are: they only match items that already exist, and they have to keep working on items in a hand-edited or synced file.src/web/api_docs.rs,docs/api.md: the new400s on the add and rename endpoints.Testing
cargo fmt,cargo clippy --all-targets(no warnings),cargo test(1201 passed) on the branch before the rebase onto feat(pantry): list items as rows, like the aisle page #653. New unit tests cover the section and name rules, including renames. CI is green on the rebased head.curlagainst a debug build:POST /api/pantry/renamewithnew_name..or../recipes/x#→400,pantry.confuntouched.POST /api/pantry/addwith the section from the issue →400.Manual check in headless Chromium (Playwright 1.63), done on the pantry page before feat(pantry): list items as rows, like the aisle page #653, with a
pantry.confcontaining the sections from the issue, a..section, and a legitimatedry goods/spicessection:PUT /api/pantry/..%2Frecipes%2FSoup.cook%23/Oregano. Remove →DELETE /api/pantry/..%2Frecipes%2FStew.cook%23/Basil. Both change only the pantry;Soup.cookandStew.cookare untouched.dry goods/spicesstill saves, throughPUT /api/pantry/dry%20goods%2Fspices/Salt...section sends no request and shows an error.Not yet repeated on feat(pantry): list items as rows, like the aisle page #653's page.
🤖 Generated with Claude Code