Repository navigation
Description
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)
recipe_rawrecipe_saverecipe_deleteis_safe_relative_path— lexical only, by design
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 itIf 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
.cookand.menu: resolve the extension explicitly instead of accepting any existing path. - Refuse path components that start with
.incheck_path. - One shared helper in
handlers/common.rsso the three handlers cannot drift apart, plus a spawned-server regression test in the style oftests/cors_test.rs.
Related
- Path traversal: shopping list API and /recipe, /directory routes read files outside the recipe directory #530 / fix(server): keep request-supplied paths inside the recipe directory #531 — traversal outside the base directory (fixed).
- feat(server): opt-in sign-in before anything can be changed #534 — sign-in would gate the writes, but the file-type problem stays for signed-in users and for the raw read.
Activity
fix(server): limit the recipe file endpoints to .cook and .menu files (…