Skip to content

Guests can read dot-files and non-recipe files from the recipe folder through /api/static and /recipe/{path}, also under --recipes-only #658

Closed

Description

@LeMyst

Summary

Visitors who are not signed in can read files from the recipe folder that are not recipes, dot-files included, through two routes:

  • /api/static/{path} is a plain ServeDir over the whole recipe folder. It is not in PROTECTED_READS, so with sign-in on, a guest with no cookie gets .git/config (remote URLs with tokens), .env, .config/gh/hosts.yml, config/pantry.conf, .shopping-list, and whatever a symlink in the folder points to. Only --recipes-only narrows it, to picture extensions.
  • /recipe/{path} (the HTML page) checks the path with is_safe_relative_path only. It does not apply the hidden-component rule fix(server): limit the recipe file endpoints to .cook and .menu files #550 added to is_request_path for /api/recipes. cooklang_find::get_recipe opens any existing file whose name has an extension, so /recipe/.config/gh/hosts.yml renders the token file as recipe steps. That is the exact case the comment on is_request_path says was closed.

Under --recipes-only, /api/static is correctly limited. But /recipe/{path} and GET /api/recipes/{path} are on the guest allowlist and are not limited to .cook/.menu, so guests still read config/pantry.conf, config/aisle.conf and the dot-files above. This breaks what #621 promises: "Not the shopping list, the pantry or anything else that happens to live there".

Affected code (at b3a8069)

Introduced by

Reproduction

Tested against the main image at ae06d8f, which differs from b3a8069 only in version numbers. The recipe folder holds Soup.cook, config/pantry.conf, config/aisle.conf, .git/config and .config/gh/hosts.yml, with fake tokens.

Sign-in on (users.toml with two users), no cookie:

GET /api/static/.git/config               200  url = https://me:ghp_FAKE…@github.com/…
GET /api/static/.config/gh/hosts.yml      200  oauth_token: gho_FAKE…
GET /api/static/config/pantry.conf        200
GET /recipe/.config/gh/hosts.yml          200  token shown as a step
GET /api/recipes/.config/gh/hosts.yml     400  (refused, as intended)

cook server --recipes-only, no users:

GET /api/static/.git/config               404  (refused, as intended)
GET /api/static/config/pantry.conf        404  (refused, as intended)
GET /recipe/.config/gh/hosts.yml          200  token shown as a step
GET /recipe/config/aisle.conf             200
GET /api/recipes/config/pantry.conf       200

The recipe folder is often a git checkout, a synced folder or part of a home directory, so tokens there are realistic.

Suggested fix

  1. /api/static refuses any path with a component starting with ., in every mode, and serves only the picture extensions it exists for (the PICTURES list). Alternatively it answers everything else with Content-Disposition: attachment and X-Content-Type-Options: nosniff, so an .html or .svg in the folder is not active same-origin content.
  2. recipe_page uses is_request_path, like edit_page already does.
  3. recipe_page and GET /api/recipes/{path} refuse a path whose extension is something other than cook/menu before calling get_recipe. Such names already 404 unless a non-recipe file matches. Longer term, cooklang_find::get_recipe could accept only .cook/.menu itself.

Static-site mode feeds recipe_page paths from the tree, which may sit in hidden folders, so the check may belong in the server's /recipe handler rather than in the builder.

🤖 Generated with Claude Code

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