Repository navigation
Description
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: "/" })atauth.ts:822. It passes nosecure, and a browser rejects a__Host-Set-Cookie that lacksSecure. - delegated mint:
generateSignedCookie(COOKIE_NAME, …)(packages/ui-server/src/middleware/principals.ts:26,144-149). Only the value is returned. - CLI:
credentialCookiesendsbrain_ui_session=<value>(packages/core/src/cli/host-client.ts:43). - docs:
docs/http-api.md:268and: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(honoprefix: "host"), with the existing attributes. - Read
__Host-brain_ui_sessionfirst, then fall back tobrain_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 carriessecure: trueandpath: "/". - 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) anddocs/hosting/README.md:364. Leavedocs/decisions/session-principals.md:230alone: 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_sessionwithSecure,HttpOnly,SameSite=Strict,Path=/and noDomain, and also expirebrain_ui_session. - A request carrying only the legacy cookie still authenticates, over HTTP and over the WebSocket upgrade.
- Logout's
Set-Cookieheaders expire both names, and the__Host-one includesSecure; Path=/.
- Password login and passkey login both set
- Real-Chrome runtime test: after sign-in,
document.cookiecannot 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 fixturepackages/ui-sdk/tests/fixtures/ordinary-identity-ws.tspass 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 lintContract impact
- This touches the integration contract, so it needs the
contractlabel, aCONTRACT:commit prefix, and the doc updated in the same commit. The documented emitted cookie name changes; the rename is ruled breaking (above) and carriesbreaking. - 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_sessioncookie, the still-accepted legacy input name, and thatbrain_ui_session=<value>remains the supportedCookie: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
schlessera commentedon Oct 22, 2026
Decision (maintainer, 2026-10-22): breaking.
Renaming the emitted browser session cookie from
brain_ui_sessionto__Host-brain_ui_sessionis classified as breaking underdocs/integration-contract.md("a field removed, renamed"). The documented emitted name changes, even though the server keeps acceptingbrain_ui_sessionon input.Required handling:
breakinglabel (contractandsecuritystay).@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 supportedCookie:header form for CLI credential files.docs/http-api.md(:268,:443) anddocs/hosting/README.md:364in the sameCONTRACT:commit. Leavesession-principals.md:230alone; 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 carriessecure: trueandpath: "/"), and keep the delegated mint and CLI unchanged. Removing the legacy input name remains out of scope and needs its own issue.needs: decisionis removed.schlessera commentedon Oct 22, 2026
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.
schlessera commentedon Oct 23, 2026
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.