Skip to content

Default CORS policy Access-Control-Allow-Origin: * lets any website read the whole server #546

Closed

Description

@LeMyst

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)

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

  1. cook server (default 127.0.0.1:9080) with the seed recipes.
  2. 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-origin is given (--cors-origin '*' keeps today's behaviour for people who rely on it).
  • Apply the same Host rule 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.md and the --cors-origin help.

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

Activity

  1. added a commit that references this issue on Sep 30, 2026
    0ef9105
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