Commit Graph
1 Commits
Author SHA1 Message Date
Cato 198d77e523 feat(auth): an agent's token opens a browser session, with the token's power and no more (#1679)
* feat(auth): an agent's token opens a browser session, with the token's power and no more

A browser cannot send a Bearer header on a page load, so a Viewer seat with a
ck_ token was sent to sign-in from /projects, /terminal, the workbench,
history and feedback.

- POST /api/token-session (Bearer ck_ only) mints a link that opens once,
  within two minutes. The link carries a random code; the server keeps its
  SHA-256 (token_sessions, migration 0138). The token is never in the link.
- GET /api/auth/loki/token-session (an AccountKit plugin endpoint) opens it:
  a session for the token's user that ends after an hour, is never
  refreshed, and is recorded as the token's before its cookie is set.
- Such a session reads like the user (pages, GET on the API) and writes only
  where a token is accepted: the proxy marks its writes and person-only
  routes read them as signed out. It never reaches tokens, a shell, the
  password, linked sign-ins or export, nor AccountKit's passkey and second
  factor endpoints. Revoking or expiring the token signs it out.

Tests: scripts/test/token-session.ts (landing paths, the refused routes, the
middleware decision, the wiring); scripts/test/token-session-db.ts in
test:db (single use, expiry, revoked and expired tokens, hash-only storage).

* style(drizzle): format the 0138 snapshot and journal
2026-11-12 22:24:41 +01:00