Repository navigation
fix(server): limit the recipe file endpoints to .cook and .menu files - #550
Merged
Merged
Conversation
GET /api/recipes/raw, PUT and DELETE /api/recipes took the joined path as-is whenever something existed there, so they read, overwrote and deleted any file under the recipe directory: config/aisle.conf, .shopping-list, a checkout's .git/config. The pattern dates from 423c0c6 (cooklang#246). All three now resolve the path through one helper, recipe_file, which only ever returns a .cook or .menu file: `Pasta` is looked up as Pasta.cook then Pasta.menu, and `config/aisle.conf` resolves to config/aisle.conf.cook. A new file keeps the extension it is given (`Week.menu` is no longer created as Week.menu.cook). The editor page opens files through the same helper. check_path also refuses any path component starting with a dot, for every /api route using it. cooklang-find opens any existing file whose name has an extension, so the parsed recipe endpoint returned .env.local as recipe steps. Closes cooklang#545 Co-Authored-By: Claude Opus 5.5 <[email protected]>
LeMyst
marked this pull request as ready for review
September 26, 2026 12:08
LeMyst
added a commit
to LeMyst/cookcli
that referenced
this pull request
Sep 27, 2026
Resolve the edit_page conflict with cooklang#550: keep its recipe_file() lookup, which already rules out a missing file path, and pass the viewer through to the error page. Add the sign-in strings to the Italian locale that arrived with cooklang#543. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #545.
What changes
GET /api/recipes/raw/{path},PUT /api/recipes/{path}andDELETE /api/recipes/{path}now only ever touch a.cookor.menufile. Before, each of them took the joined path as it was whenever something existed there, so they read, overwrote and deletedconfig/aisle.conf,.shopping-list, a checkout's.git/configor anything else under the served directory.recipe_fileinhandlers/common.rsrunscheck_path, then resolves the request path to a recipe or menu file.Pasta.cookandPlan.menuname those files.Pastais looked up asPasta.cook, thenPasta.menu. A path naming anything else never resolves to it:config/aisle.confbecomesconfig/aisle.conf.cook, so raw and delete answer 404 and a save writes a new recipe beside it instead of overwriting it. The three handlers lost their copies of the old lookup, so they cannot drift apart again.check_pathnow also refuses any component starting with., as the issue suggested. That covers every/apiroute using it, not just these three. It matters beyond raw/save/delete:cooklang-findopens any existing file whose name has an extension, soGET /api/recipes/.env.local(or.config/gh/hosts.yml) used to parse the file and return its lines as recipe steps./edit/{path}now opens a file through the same resolver. It used to open any filecooklang-findwould, which showedconfig/aisle.confin an editor whose Save could no longer write it back.Behaviour changes worth a look
Week.menuis now created asWeek.menu, notWeek.menu.cook. The same goes forNew.cook, which used to becomeNew.cook.cook. Without an extension it is still created as.cook.Breakfast) now resolves toBreakfast.cook. Before, the raw endpoint tried to read the directory and answered 500.cooklang-find's index still lists them, since its glob matches hidden folders, so they show up in the listing but the editor refuses to open them. A.trash/folder is the realistic case. I think refusing them is the right trade, but it is a visible change.Not in this PR
These read paths stay open and are better handled separately:
/api/static/{path}is aServeDirover the whole recipe directory, so/api/static/config/aisle.confand/api/static/.git/configare still served as-is. Limiting it to media types is its own change./recipe/{path}and the parsedGET /api/recipes/{path}still go throughcooklang_find::get_recipe, which accepts any existing file with an extension. The API side now refuses hidden paths, but it still renders a visible file likeconfig/aisle.confas steps. The recipe page builder was left alone because static-site mode feeds it index paths, which may sit in hidden folders. The clean fix is forget_recipeto accept only.cook/.menu.Tests
tests/recipe_file_api_test.rsbootscook serveron a folder holding a recipe and a menu next toconfig/aisle.conf,config/pantry.conf,.shopping-list,.git/config,.env.localandnotes.txt. It checks that raw, PUT, DELETE and the editor page still work on the recipe and the menu and leave every other file unread, unchanged and in place. It also checks that the parsed endpoint refuses.env.local. The requests carry noOrigin, likecurlfrom another machine, so the cross-site write guard does not interfere. The server runs throughcommon::with_isolated_config.handlers/common.rscover the resolver and the hidden-component rule.main(e65180f), all five new integration tests fail. Raw, DELETE and the parsed endpoint answer 200 on the other files, and the editor opensconfig/aisle.conf. The save test fails first on its new-file check, sinceStew.cookis created asStew.cook.cook, before it reaches the overwrite check.cargo fmt,cargo clippy --all-targetsandcargo testpass.docs/api.mdis regenerated from the updated API reference.🤖 Generated with Claude Code