Repository navigation
Description
Summary
The pantry page builds its edit and remove requests as
fetch(`{{ prefix }}/api/pantry/${section}/${encodeURIComponent(name)}`, { method: 'PUT', … })name is encoded, but section is not. It comes straight from the pantry file through data-section. POST /api/pantry/add only trims the section name, so a section named ../recipes/Soup.cook# is accepted and stored. When someone later edits or removes an item in that section, the browser normalises the URL to /api/recipes/Soup.cook (the # turns the rest into a fragment). The request then carries their cookie:
- Edit → Save sends
PUT /api/recipes/Soup.cookwith{"quantity":"2"}, which replaces the recipe. - Remove sends
DELETE /api/recipes/Stew.cook, which deletes the recipe.
With roles (#563), a shopper, who may change the pantry but not recipes, can get an editor's or admin's click to overwrite or delete any recipe. The activity log then names the editor. Without sign-in, the same happens from a config/pantry.conf that arrives through sync or git.
Affected code (at b3a8069)
data-section="{{ section.name }}"- edit
fetchand removefetch;sectionis also unescaped inquerySelector AddPantryItem::trimmed: no check on the section's characters
Introduced by
8a5867d (feat: pantry ui), which added the URL template. #563 made it cross a privilege boundary.
Reproduction
Tested against the main image at ae06d8f, which differs from b3a8069 only in version numbers. users.toml has sam (shopper) and ed (editor).
samsigns in and runsPOST /api/pantry/addtwice:{"section":"../recipes/Soup.cook#","name":"Oregano","quantity":"1"}, then the same withStew.cook→ 200. For comparison,sam's ownPUT /api/recipes/Soup.cook→ 403.edsigns in (headless Chromium), opens/pantry, clicks Edit on the first Oregano, sets quantity 2 and saves, then clicks Remove on the second one and confirms.- The browser sent
PUT /api/recipes/Soup.cookandDELETE /api/recipes/Stew.cook.Soup.cooknow contains{"quantity":"2"}andStew.cookis gone. The activity log saysed updated recipe "Soup.cook"anded deleted recipe "Stew.cook".
The odd section heading is visible on the page and in the remove confirmation, so it takes an inattentive click. The edit path has no confirmation at all.
Suggested fix
encodeURIComponent(section)in bothfetchcalls, andCSS.escape(section)in the selectors.- On the server, refuse section names (and item names) containing
/,\,#,?or control characters inPOST /api/pantry/addandPUT /api/pantry/{section}/{name}. Pantry sections are TOML table names, so nothing legitimate needs them.
🤖 Generated with Claude Code
Activity
drawmeanelephant commentedon Oct 10, 2026
Heads-up for triage: the client half of this is already covered by open PR #629, which URL-encodes the section in the update/remove fetches and
CSS.escapes it in the selector after removal.What #629 does not add is the server-side half — refusing
/,\,#,?(and control characters) in section and item names atPOST /api/pantry/addandPUT /api/pantry/{section}/{name}. That part is still open if #629 lands first.fix(server): keep pantry edits inside /api/pantry
fix(server): keep pantry edits inside /api/pantry
fix(server): keep pantry edits inside /api/pantry (cooklang#666)