Repository navigation
Description
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 plainServeDirover the whole recipe folder. It is not inPROTECTED_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-onlynarrows it, to picture extensions./recipe/{path}(the HTML page) checks the path withis_safe_relative_pathonly. It does not apply the hidden-component rule fix(server): limit the recipe file endpoints to .cook and .menu files #550 added tois_request_pathfor/api/recipes.cooklang_find::get_recipeopens any existing file whose name has an extension, so/recipe/.config/gh/hosts.ymlrenders the token file as recipe steps. That is the exact case the comment onis_request_pathsays 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)
/api/static→ServeDir::new(&state.base_path),PROTECTED_READS(no/api/static)recipe_pagepath check:is_safe_relative_pathonly, thenget_recipeGET /api/recipes/{path}:check_path(no dot-files), but any extensionis_request_path: its comment describes the.config/gh/hosts.ymlreadRECIPE_READS:/recipeand/api/recipesare open to--recipes-onlyguests
Introduced by
/api/staticserving the whole folder: e200582 (feat: new UI)/recipe/{path}without the dot-file rule: 9652975 (fix(server): keep /recipe and /directory inside the recipe directory, fix(server): keep request-supplied paths inside the recipe directory #531), then 6ff6f9c (fix(server): limit the recipe file endpoints to .cook and .menu files #550), which addedis_request_pathto the API handlers only- The
--recipes-onlyallowlist trusting both routes: d682b15 (feat(server): --recipes-only shows guests only the recipes #621)
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
/api/staticrefuses any path with a component starting with., in every mode, and serves only the picture extensions it exists for (thePICTURESlist). Alternatively it answers everything else withContent-Disposition: attachmentandX-Content-Type-Options: nosniff, so an.htmlor.svgin the folder is not active same-origin content.recipe_pageusesis_request_path, likeedit_pagealready does.recipe_pageandGET /api/recipes/{path}refuse a path whose extension is something other thancook/menubefore callingget_recipe. Such names already 404 unless a non-recipe file matches. Longer term,cooklang_find::get_recipecould accept only.cook/.menuitself.
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
Activity
fix(server): serve only recipes and pictures from the recipe folder (c…
fix(server): hold recipe_image to the recipe-extension rule (#750)