Skip to content

fix(server): hold recipe_image to the recipe-extension rule - #750

Merged
LeMyst merged 1 commit into
cooklang:mainfrom
drawmeanelephant:fix/697-recipe-image-recipe-only
Oct 17, 2026
Merged

LeMyst merged 1 commit into
cooklang:mainfrom
drawmeanelephant:fix/697-recipe-image-recipe-only

Conversation

@drawmeanelephant

Copy link
Copy Markdown
Contributor

Closes #697

Summary

GET/PUT/DELETE /api/recipe_image/{*path} accepted any file under the recipe directory, not just .cook/.menu recipes. find_recipe ran check_path but never is_recipe_request — the extension allowlist handlers/recipes.rs has applied since #658 for exactly this reason (cooklang-find opens a name with an extension as it is).

Consequences verified live:

  • GET /api/recipe_image/config/pantry.conf → 200 with the pantry's contents returned as step text.
  • PUT wrote config/notes.jpg-style files beside any file; DELETE removed {stem}.{jpg,jpeg,png,webp} beside any file.

Changes

find_recipe now refuses a non-.cook/.menu path with the same 404 /api/recipes/ returns — which covers GET, PUT and DELETE since all three resolve the recipe through it.

Test plan

  • New integration test a_non_recipe_file_is_not_a_recipe in tests/recipe_image_api_test.rs: config/pantry.conf and notes.txt get 404 on all three verbs and nothing is written or removed.
  • Existing 17 endpoint tests still pass.

Generated with Devin

@LeMyst LeMyst left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. find_recipe is the only way in for GET (title and step), PUT and DELETE, so this covers the endpoint. The editor always sends .cook or .menu (edit_page redirects extensionless paths), so names with dots like Mr. Smith's Stew are unaffected. The test fails without the change and is Windows-safe.

  • Nit: recipes.rs logs tracing::error! before the same 404; this path doesn't.
  • Possible follow-up, same kind of bug: POST /api/shopping_list and /api/shopping_list/add only call check_path, so config/pantry.conf can be parsed as a recipe. Only @ tokens leak, so it's small.

This conflicts with #751, which also rewrites find_recipe. The resolved order would be check_path → extension check (404) → get_recipe → inside_collection.


🤖 Analysis and recommendations made by Claude (Anthropic's AI assistant), posted on behalf of @LeMyst.

`cooklang-find` opens a name with an extension as it is, so
`/api/recipe_image/config/pantry.conf` parsed the pantry configuration
and returned its contents as step text, while PUT and DELETE wrote and
removed `pantry.{jpg,png,...}` beside it. `is_recipe_request` is the
`.cook`/`.menu` allowlist `/api/recipes/` already applies for the same
reason (#658); `find_recipe` applies it now too.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@drawmeanelephant
drawmeanelephant force-pushed the fix/697-recipe-image-recipe-only branch from ca60bff to d15ed18 Compare October 14, 2026 13:28
@drawmeanelephant

Copy link
Copy Markdown
Contributor Author

Added the tracing::error! before the extension-check 404, matching recipes.rs. And agreed on the merge order with #751 — check_path → extension (404) → get_recipe → inside_collection; whichever lands second inherits it.

@LeMyst

LeMyst commented Oct 17, 2026

Copy link
Copy Markdown
Collaborator

Thanks. The tracing::error! before the extension-check 404 (src/server/handlers/recipe_image.rs:358) matches recipes.rs, and the order is the one agreed with #751: check_path → extension (404) → get_recipe → inside_collection. CI is green on d15ed18, so this looks good to merge.

git merge-tree with #751 still conflicts in recipe_image.rs, in two mechanical hunks:

#751's not_found helper could also serve this PR's 404.


🤖 Analysis and recommendations made by Claude (Anthropic's AI assistant), posted on behalf of @LeMyst.

@LeMyst
LeMyst merged commit 5822cf8 into cooklang:main Oct 17, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

/api/recipe_image/{*path} accepts any file, not just .cook/.menu recipes

2 participants