~ knotless Search/
↑↓ move↵ open⇧↵ all results
0
0

The console's cookie is __Host-, and only its own pages use it

Merged
Merged chadtmiller.com asked to merge into main from chadtmiller.com/group-host:host/cookie

Where the console is on https, its cookies are now __Host- and Secure, so no page at a name beside the console's, such as a group's address, can set one in their place. A request whose Origin is not the console's is taken as nobody's, whatever cookie it carries, and can't switch accounts or sign out.

Claude Opus 5.5

What changes

The cookies' names (console_login.rs). Host::cookie_name puts __Host- before each cookie's name when CONSOLE_URL is https: the session, the sign-in under way, and the other accounts signed in. Every cookie the host sets is already Path=/, has no Domain, and is Secure there, as __Host- requires. Over http, as in tests reaching the host directly, they keep their names, and a browser would refuse a __Host- cookie that isn't Secure anyway. Reading one goes through Host::cookie_of, by the same name. The MCP server's calls in place of a member name it the same way.

Where a cookie is taken from.

  • Host::console_caller answers nobody for a request whose Origin is not CONSOLE_URL's origin. That covers every method a cookie authenticates, and /img.
  • /console/switch and /console/logout refuse such a request with 403, setting no cookie. Otherwise a page elsewhere could still clear the session or swap accounts by the cookies alone.
  • A request saying no Origin is answered as before. That is how a browser's own navigations, its same-origin GETs, the console's server calling the host, and the MCP server's calls come.

Docs.

  • docs/design/signing-in.md says what the cookie is named and where it is taken from.
  • docs/reference/api.md names it.
  • docs/reference/config.md's CONSOLE_URL row says it is the one Origin the cookie is taken from.
  • docs/design/sites.md's sandbox section names both as the host's own guard beside the sandbox.

Why

It is the item of at://did:plc:bcgltzqazw5tb6k2g3ttenbj/space/dev.knotless.space/group-host/did:plc:bcgltzqazw5tb6k2g3ttenbj/dev.knotless.issue/3mzlk7gxpmi3j that comes before a page the host serves around a group's site holds sessions. A group's address is under the host's domain, so its pages are the same site as the console. The sandbox keeps those pages from carrying the console's cookie, and a browser test pull checks that it does. This makes the host refuse it on its own, should any page reach it without the sandbox:

  • Without __Host-, a page at riders.groups.example.com could set a group_host_session cookie for .example.com, which the console would then receive in place of the person's own.
  • Without the Origin rule, a same-site request carries a SameSite=Lax cookie.

How it was checked

  • New a_session_is_the_consoles_alone_and_only_its_pages_use_it (tests/console_login.rs), with the console on https:

    • the cookie is named __Host-group_host_session;
    • getViewer names its holder with no Origin or the console's, and nobody from a group's address, from null (a sandboxed page), or from the console's name on another port;
    • the plain name is nobody's;
    • /console/switch and /console/logout from a group's address answer 403 with no Set-Cookie, and the person stays signed in;
    • from the console's Origin, signing out clears __Host-group_host_session as it was set (Path=/; HttpOnly; SameSite=Lax; Max-Age=0; Secure).
  • tests/group_config.rs names its cookie by cookie_name, its host's console being https.

  • Locally:

    • just t -p group-host --test console_login --test group_config --test mcp --test account_move passes;
    • clippy passes;
    • just e2e passes all its flows: signing in through the PDS, switching accounts, signing out, and every form, each sending the console's Origin through its server or none.

    Coverage and the rest are left to CI.

Shortcomings

  • just serve with just web-dev. There the console (on its own port) is not CONSOLE_URL, so a browser's own calls to the host would be nobody's. That console can't sign anyone in either, as signing in needs https at a name, so this changes nothing there. just dev, just look and e2e set CONSOLE_URL to the console's address.
  • Signing in afresh. Cookies signed before this deploy keep their old name, which the host no longer reads where the console is on https, so everyone signed in signs in again once.
Approved

This pull names the console's cookies __Host- where CONSOLE_URL is https. It also treats a request whose Origin is not the console's as nobody's, and answers 403 to /console/switch and /console/logout from such a request. I read every changed file and found nothing wrong.

  • Cookie reads: a search finds no other reader of the session cookie. The old public cookie_of is gone, and the two remaining users of COOKIE (the MCP caller and the group_config test) now go through cookie_name.
  • Logout: logout checks Origin before console_caller, and the cookies it clears use the same __Host- name that was set, so sign-out works.
  • Origin match: the comparison is exact on the serialized origin. That is why null and the same name on another port are refused, and the new test covers both.
  • Docs and tests: the docs are updated with the change as AGENTS.md asks, and the new test covers the behaviours the body claims.

One small thing to know: asked_elsewhere calls expect on parsing CONSOLE_URL for every request. That is safe as long as config rejects a bad URL at startup.

Merged as a7aa5f3