Repository navigation
Description
Summary
Without --cors-origin, the server answers every GET with Access-Control-Allow-Origin: *. Browsers therefore let any page the user visits read responses from a local cook server: the recipe collection, anything under /api/static/, the sync status (including the pending device code), and the HTML of /preferences and /edit/… with the absolute base path in it.
#523 fixed the same problem for writes (a rebound DNS name or a foreign origin can no longer modify recipes). Reads were left as they were, and there is no Host allowlist for them either, so a rebound name still reaches every read route, the SSE stream and the WebSocket.
Affected code (at e65180f)
CorsConfig::from_args— no flag ⇒CorsOrigins::AnyCorsConfig::layer—AllowOrigin::any()mod.rs— the layer wraps the whole app, UI pages included
Introduced by
The permissive layer has been there since the Rust rewrite (11adb04, #78). The wildcard became the explicit, documented default in 979addf / 26f7bf0 (#484, --cors-origin).
Reproduction
cook server(default127.0.0.1:9080) with the seed recipes.- Open any website, then in its devtools console:
fetch('http://127.0.0.1:9080/api/recipes').then(r => r.json()).then(console.log)
fetch('http://127.0.0.1:9080/api/recipes/raw/Breakfast/Easy Pancakes').then(r => r.text()).then(console.log)
fetch('http://127.0.0.1:9080/api/sync/status').then(r => r.json()).then(console.log)
fetch('http://127.0.0.1:9080/preferences').then(r => r.text()).then(console.log)All four succeed. (Chrome's Local Network Access prompt can block the first request from a public site; Firefox and Safari have no such prompt, and a page on the LAN is not covered at all.)
Impact
Any site can quietly copy the user's whole recipe collection and whatever else lives in the served folder, learn the absolute path of the folder and the sync account email, and — while a sync login is pending — read the device code (see #547). Combined with #545, "whatever else" is any file in the folder.
Suggested fix
- Default to same-origin: emit no CORS headers unless
--cors-originis given (--cors-origin '*'keeps today's behaviour for people who rely on it). - Apply the same
Hostrule as the write guard (CorsConfig::trusts) to reads, so a rebound name is refused everywhere, not just on writes. - Document the behaviour change in
docs/server.mdand the--cors-originhelp.
This is a deliberate default at the moment, so flagging it as needs discussion: is there a known consumer of the wildcard (external front-end, mobile app) that would break?
Related
- fix(server): trust only localhost and IP addresses as the server's own origin #523 — same rule, writes only.
- fix(server): refuse cross-site WebSocket connections to the language server #524 — origin check for the WebSocket.
Activity
fix(server): same-origin by default, and refuse unknown Host names (c…