Skip to content

ui-server: the browser session cookie is named __Host-brain_ui_session #2562

Open

Description

@schlessera

Context

The browser session cookie is named brain_ui_session (COOKIE_NAME, packages/ui-server/src/middleware/auth.ts:61). It is set with httpOnly, sameSite: "Strict", secure: true and path: "/", and no Domain (issueSessionCookie, auth.ts:336-345). It already meets every condition of the __Host- prefix but does not use it. The browser therefore does not enforce those conditions: a sibling subdomain, or a plain-HTTP response on the same host, can still plant or shadow a brain_ui_session cookie.

Guide security/security §1.3: "Name first-party session cookies with the __Host- prefix … when used by a single domain. This requires Secure …, Path=/ …, and omitting the Domain attribute, protecting against same-site and network attackers."

Places that use the name:

  • read: resolveCookiePrincipal (getSignedCookie(c, secret, COOKIE_NAME), auth.ts:418). This one read path also serves the WebSocket upgrade.
  • delete on logout: deleteCookie(c, COOKIE_NAME, { path: "/" }) at auth.ts:822. It passes no secure, and a browser rejects a __Host- Set-Cookie that lacks Secure.
  • delegated mint: generateSignedCookie(COOKIE_NAME, …) (packages/ui-server/src/middleware/principals.ts:26, 144-149). Only the value is returned.
  • CLI: credentialCookie sends brain_ui_session=<value> (packages/core/src/cli/host-client.ts:43).
  • docs: docs/http-api.md:268 and :443, docs/integration-contract/cli.md:990, docs/hosting/README.md:364.

The lock-pinned Hono 4.13.10 signs the value only (makeSignature(value, secret)), so a signed value is valid under either name. Its setters/deleter accept { prefix: "host" }; getSignedCookie(c, secret, key, "host") takes the prefix as its fourth argument. The host-prefixed writer forces Secure, Path=/ and no Domain. Verified against the integrity-matched npm tarball; this is source verification, not a browser-cookie run.

Recorded decision — 2026-10-22

The maintainer ruling classifies the emitted-name rename as breaking despite preserved legacy input. Carry contract, breaking and security. Update the named authoritative docs in the same CONTRACT: commit. No cookie-policy choice remains.

Release classification (maintainer, 2026-10-24): before 1.0.0 an approved break ships as a minor changeset that names the break, never a major one (docs/decisions/contract-versioning.md:14-20). Under the lockstep fixed group a literal major bump would publish 1.0.0, which is reserved for the stability bar. This replaces the ruling's "major changeset" wording; the breaking classification itself stands.

Scope

  • Issue the browser session as __Host-brain_ui_session (hono prefix: "host"), with the existing attributes.
  • Read __Host-brain_ui_session first, then fall back to brain_ui_session. Both go through the same signature, format and principal checks.
  • When issuing a new cookie, and on logout, delete both names. The __Host- deletion carries secure: true and path: "/".
  • Delegated principal mint and the CLI stay unchanged: the returned value is name-independent and the legacy name is still accepted. Document that brain_ui_session=<value> remains the supported header form for credential files.
  • Update docs/http-api.md (lines 268 and 443) and docs/hosting/README.md:364. Leave docs/decisions/session-principals.md:230 alone: it is history.

Out of scope

  • Removing support for the legacy name. That would need its own breaking issue.
  • Changing SameSite, TTL or signing.
  • Changing the CLI's header (packages/core).

Acceptance criteria

  • The emitted-name rename is ruled breaking on this issue before implementation.
  • Server tests, each failing before the change:
    • Password login and passkey login both set __Host-brain_ui_session with Secure, HttpOnly, SameSite=Strict, Path=/ and no Domain, and also expire brain_ui_session.
    • A request carrying only the legacy cookie still authenticates, over HTTP and over the WebSocket upgrade.
    • Logout's Set-Cookie headers expire both names, and the __Host- one includes Secure; Path=/.
  • Real-Chrome runtime test: after sign-in, document.cookie cannot see the cookie, the browser jar holds __Host-brain_ui_session, and "Sign out everywhere" removes it from the jar.
  • The existing ui-react runtime suites (e.g. packages/ui-react/tests/auth-expiry-runtime.test.ts) and the ui-sdk fixture packages/ui-sdk/tests/fixtures/ordinary-identity-ws.ts pass unchanged.
  • The PR records a meaningful mutation of the actual logout cleanup: omit the __Host- deletion and watch the logout browser-jar assertion fail, then restore it. Merely dropping an explicit secure option while keeping Hono prefix:"host" is not a valid mutation: the verified helper forces Secure itself. If checking browser prefix rejection separately, use an intentionally invalid raw Set-Cookie control and distinguish that control from the production deletion path.

Verification

bun run test packages/ui-server/tests
bun run test packages/ui-react/tests/auth-expiry-runtime.test.ts   # BRAIN_REQUIRE_CHROME=1
bun run test
bun run typecheck
bun run lint

Contract impact

  • This touches the integration contract, so it needs the contract label, a CONTRACT: commit prefix, and the doc updated in the same commit. The documented emitted cookie name changes; the rename is ruled breaking (above) and carries breaking.
  • This changes a published package's behaviour, so it needs a changeset: a minor changeset for @schlessera/brain-ui-server (pre-1.0 policy) that names the break, the new emitted __Host-brain_ui_session cookie, the still-accepted legacy input name, and that brain_ui_session=<value> remains the supported Cookie: header form for CLI credential files. Do not write a major changeset.

2026-10-24: replaced the "major changeset" instruction with the pre-1.0 minor changeset naming the break (maintainer, 2026-10-24); removed the superseded readiness-reconciliation note (history is in the comments).

Activity

  1. added
    type: feat
    area: ui-server
    priority: p3
    needs: decision
    contract
    security
    on Oct 22, 2026
  2. schlessera commented on Oct 22, 2026

    @schlessera
    OwnerAuthor

    Decision (maintainer, 2026-10-22): breaking.

    Renaming the emitted browser session cookie from brain_ui_session to __Host-brain_ui_session is classified as breaking under docs/integration-contract.md ("a field removed, renamed"). The documented emitted name changes, even though the server keeps accepting brain_ui_session on input.

    Required handling:

    • Add the breaking label (contract and security stay).
    • Add a major changeset for @schlessera/brain-ui-server. It names the new emitted cookie and states that the legacy name is still accepted on input and is still the supported Cookie: header form for CLI credential files.
    • Update docs/http-api.md (:268, :443) and docs/hosting/README.md:364 in the same CONTRACT: commit. Leave session-principals.md:230 alone; it is history.

    The scope and acceptance criteria are unchanged: emit __Host- with the existing attributes, read __Host- first and fall back to the legacy name, delete both names on issue and on logout (the __Host- deletion carries secure: true and path: "/"), and keep the delegated mint and CLI unchanged. Removing the legacy input name remains out of scope and needs its own issue.

    needs: decision is removed.

  3. added
    breaking
    agent-ready
    and removed
    needs: decision
    on Oct 22, 2026
  4. schlessera commented on Oct 22, 2026

    @schlessera
    OwnerAuthor

    2026-10-22 readiness reconciliation: folded the maintainer ruling into the body, replacing the unresolved-choice specification and aligning scope/criteria with the accepted branch. The remaining work is explicitly scoped; add agent-ready. Preserve priority, native parent, assignment and release attribution. This is issue preparation, not implementation, runtime proof or delivery.

  5. schlessera commented on Oct 23, 2026

    @schlessera
    OwnerAuthor

    Release classification (maintainer, 2026-10-24): before 1.0.0 an approved breaking change ships as a minor changeset that names the break, never a major one. Under the lockstep fixed group a major changeset would publish 1.0.0 (docs/decisions/contract-versioning.md:14-20). The breaking classification of this rename stands; only the changeset level in the 2026-10-22 ruling's "Required handling" changes. The body's Contract impact now says this.

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

    agent-readyarea: ui-serverbreakingcontractpriority: p3securitytype: feat

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions