Skip to content

Pantry section names go into request URLs unencoded: a shopper can make an editor overwrite or delete a recipe #659

Closed

Description

@LeMyst

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.cook with {"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)

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).

  1. sam signs in and runs POST /api/pantry/add twice: {"section":"../recipes/Soup.cook#","name":"Oregano","quantity":"1"}, then the same with Stew.cook → 200. For comparison, sam's own PUT /api/recipes/Soup.cook → 403.
  2. ed signs 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.
  3. The browser sent PUT /api/recipes/Soup.cook and DELETE /api/recipes/Stew.cook. Soup.cook now contains {"quantity":"2"} and Stew.cook is gone. The activity log says ed updated recipe "Soup.cook" and ed 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 both fetch calls, and CSS.escape(section) in the selectors.
  • On the server, refuse section names (and item names) containing /, \, #, ? or control characters in POST /api/pantry/add and PUT /api/pantry/{section}/{name}. Pantry sections are TOML table names, so nothing legitimate needs them.

🤖 Generated with Claude Code

Activity

  1. added
    bug
    area: server
    on Oct 10, 2026
  2. drawmeanelephant commented on Oct 10, 2026

    @drawmeanelephant
    Contributor

    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 at POST /api/pantry/add and PUT /api/pantry/{section}/{name}. That part is still open if #629 lands first.

  3. added 2 commits that reference this issue on Oct 10, 2026
    5090c4c
    1deb93a
  4. added a commit that references this issue on Nov 16, 2026
    ad7c9a9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: serverbug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions