Skip to content

Sync login can be hijacked: /api/sync/login/logout need no authentication and /api/sync/status exposes the pending device code #547

Closed

Description

@LeMyst

Summary

The web UI's CookCloud controls are plain API calls with no authentication. Anyone who can reach the server can log the current account out, start a new device-code login, and read the resulting user_code / verification_uri_complete from /api/sync/status. Approving that code with their own cook.md account makes the server sync the victim's recipe folder with the attacker's account, in both directions, from then on.

Affected code (at e65180f)

  • sync_status — returns user_code and verification_uri_complete of the pending flow to any caller
  • sync_login and sync_logout — guarded only by the CSRF write guard, which deliberately trusts requests that carry no Origin
  • preferences.html — one-click login button

Release binaries carry the sync feature by default; the Docker image is built without it.

Introduced by

6aa725c (feat(sync): OAuth 2.0 device-code login for CLI and Docker users, #347).

Reproduction

On a LAN against cook server --host:

curl -X POST http://host:9080/api/sync/logout
curl -X POST http://host:9080/api/sync/login
curl        http://host:9080/api/sync/status
# → {"pending_login":{"user_code":"ABCD-EFGH","verification_uri_complete":"https://cook.md/…"}, …}

Open verification_uri_complete while signed in to the attacker's cook.md account and approve. The server stores the session and starts syncing.

Cross-site variants, with the default CORS policy (#546) and no anti-framing header: a page the user is visiting polls /api/sync/status while the user is in the middle of a legitimate login and approves the code first; or it frames /preferences and clickjacks the login button.

Impact

  • The whole recipe folder — and every other file type the client syncs — is copied to an account the user does not control, continuously.
  • Sync is bidirectional: files from the attacker's account are written into the victim's folder and remote deletions are applied locally. The client currently trusts server-supplied paths (Client writes and deletes server-supplied paths without confining them to the base directory cooklang-sync#28), which turns this into arbitrary file writes.
  • Nothing warns the user; the preferences page just shows "logged in" with a different email.

Suggested fix

  • Hand user_code / verification_uri_complete only to the request that started the flow (return them once from /api/sync/login, not from /api/sync/status), and require same-origin for it.
  • Refuse /api/sync/login and /api/sync/logout unless the request comes from the loopback interface or a signed-in user. feat(server): opt-in sign-in before anything can be changed #534 already lists /api/sync/… among the routes it protects when sign-in is on; this issue is about the default, unauthenticated mode that --host and the release binaries ship with.
  • Clear the pending flow on logout, and show which account the server is about to sync with before the first sync runs.

Related

Activity

  1. LeMyst commented on Oct 10, 2026

    @LeMyst
    CollaboratorAuthor

    Re-checked at b3a8069 (0.38.1). With sign-in on, this is covered:

    • PROTECTED_READS maps /api/sync to Capability::Administer, so GET /api/sync/status (device code, linked email) needs an admin.
    • POST /api/sync/login, cancel_login and logout are not in WRITES, so they default to Administer too.
    • /preferences shows the sync controls to admins only.

    Without a users file, anyone who can reach the server can still drive the link. But that server is open by design, and it says so at startup ("Anyone who can reach this server can change your recipes"). Browsers are still stopped by the Origin check, and a curl client could change everything else anyway.

    Unless you want the open-server case handled separately (e.g. by refusing sync login from a non-loopback client when sign-in is off), I think this can be closed as fixed by #534 / #563.

    🤖 Generated with Claude Code

  2. added
    bug
    area: server
    on Oct 10, 2026
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

    area: serverbug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions