Skip to content

Server reads files outside the recipe directory via references in menu/recipe content #696

Closed

Description

@drawmeanelephant

Suggested labels: bug, area: server


Discovery audit finding H3 (high) — cooklang/cookcli @ 7c2f48b (v0.38.1), audited 2026-10-12. Repro verified live against cook server. Security-relevant: unauthenticated read of files outside the served directory.

Summary

The server reads files outside the recipe directory via references written in menu/recipe content.

Where

  • src/util/menu.rs:33-57 — only ../-prefixed menu references are resolved/checked
  • src/util/recipe_info.rs:32-33, src/web/builders.rs:429-437,499-503 — raw reference path joined onto the base dir
  • cooklang-find's fetcher does base_dir.join(name) with no containment check

Repro

Server rooted at srv/recipes; create srv/../outside/Outside.cook with servings: 7.

  1. Menu srv/recipes/Menus/Evil.menu containing - @./Sub/../../../outside/Outside{4%servings}:
    GET /api/menus/Menus/Evil.menu returns "scale": 0.5714285714285714 (= 4/7 — the server read the outside file's servings). The absolute variant @.//tmp/.../Outside{4%servings} works too.
  2. POST /api/shopping_list/add_menu persists the outside path into .shopping-list.
  3. Recipe page: srv/recipes/Mains/Stew.cook with @../Outside{6%kg} links ?scale=0.5, computed from the outside file's yield: 12%kg — while the correct in-collection target recipes/Outside.cook (yield: 6%kg) is ignored. So ../ also resolves to the wrong file (core's resolve_reference says writer-relative).

Under --recipes-only, /recipe/{path} is guest-readable, so this is reachable unauthenticated.

Expected

Recipe references are confined to the recipe directory; a reference that escapes it is refused or reported as unresolvable.

Actual

The server reads files outside the collection and discloses derived data (servings/yield → scale factors) in API responses.

Acceptance criteria (red → green)

  • Red: GET /api/menus/Menus/Evil.menu returns "scale": 0.5714… derived from the outside file.
  • Green: the same request reports the reference as unresolvable (or 404s), and no outside path is persisted to .shopping-list.

Verification

Executed repro, verified live.

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions