Skip to content

Recipe API reads, overwrites and deletes any file under the recipe directory #545

Closed

Description

@LeMyst

Summary

GET /api/recipes/raw/{path}, PUT /api/recipes/{path} and DELETE /api/recipes/{path} operate on whatever file the request names under the recipe directory, not only .cook/.menu files. Each handler takes the joined path as-is if it exists, and only falls back to appending .cook/.menu when it does not. The shape check in front of them (check_path → is_safe_relative_path) refuses .., absolute paths and drive letters, but is fine with dot-files and config/.

#531 closed escaping outside the recipe directory; this is about what is reachable inside it.

Affected code (at e65180f)

let file_path = if recipe_path.exists() {
    recipe_path            // any file, any extension
} else {
    // … try .cook, then .menu
};

Introduced by

423c0c6 (feat(api): add GET /api/recipes/raw/{path} endpoint, merged in #246) added the raw endpoint with the "use the path as-is when it exists" pattern; recipe_save and recipe_delete share it from the same editor work.

Reproduction

Against cook server --host (the Docker image's default command), from any machine on the network. curl sends no Origin, so the CSRF write guard does not apply:

curl -X PUT    http://host:9080/api/recipes/config/aisle.conf --data 'x'   # overwrites aisle.conf
curl -X DELETE http://host:9080/api/recipes/config/pantry.conf             # deletes it
curl           http://host:9080/api/recipes/raw/.shopping-list             # reads it

If the served folder is a git checkout, PUT /api/recipes/.git/config with

[core]
	fsmonitor = <any command>

runs that command on the owner's next git status. base_path defaults to the current directory (src/main.rs), so a server started from $HOME exposes .bashrc and .ssh/authorized_keys the same way.

Impact

Anyone who can reach the server — a LAN with --host, or a script running on the server's own origin (a same-origin XSS such as #548 passes the write guard) — can read, overwrite or delete any file under the served directory, including dot-files and configuration. With a git checkout or a home directory that is code execution as the server's user.

Suggested fix

  • Restrict raw/save/delete to .cook and .menu: resolve the extension explicitly instead of accepting any existing path.
  • Refuse path components that start with . in check_path.
  • One shared helper in handlers/common.rs so the three handlers cannot drift apart, plus a spawned-server regression test in the style of tests/cors_test.rs.

Related

Activity

  1. added a commit that references this issue on Sep 26, 2026
    6ff6f9c
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