Decision ADR-0012 · The Lighthouse
The owner's identity, from a passkey and a signed cookie
Accepted ·
Context
Kenil wants an admin portal for moderation and messages. He also wants visitors to see when he's on the site: a crown in the 3D world and in chat, a "Kenil is online" chip, and an arrival toast. He also wants an incognito switch. All of that needs one thing: proof that a browser belongs to the owner. The proof has to be phishing-resistant, need no password to leak, and work for both the API (Lambda) and the real-time server.
Decision
- Sign-in: passkeys only (WebAuthn), via SimpleWebAuthn (MIT).
- User verification is required, and passkeys are discoverable.
- The relying party is the site's domain (
localhostin development). - The first passkey registers with a one-time setup code that
pnpm --filter @kp/api admin:setupprints; only its hash is stored, it lasts 15 minutes, and it works once. More devices are added from inside the portal. - Every options request stores a challenge that can be used once, within 5 minutes; verification consumes it atomically.
- Recovery:
admin:resetremoves every passkey. It needs access to the table itself, which only Kenil has. - Session: an HMAC-SHA256 token (
OWNER_SECRET, SSM at M6) with a 12-hour lifetime. It lives in the cookiekp_owner:HttpOnly; SameSite=Strict; Path=/, plusSecurein production.- The browser sends it with
/api/*and with the/rtWebSocket upgrade, because both are the same origin. - Page scripts never see it.
- Signing and verifying live in
@kp/shared/server, a server-only entry point.
- The browser sends it with
- API:
requireOwnerfor every admin route. Mutations also need the site's Origin and anx-kp-admin: 1header. Sign-in attempts are rate-limited per network. - Real-time server:
- The cookie is checked at upgrade.
- The owner joins as one fixed session (
owner, "Kenil Gor", gold) on every tab and device. - Owner sessions get no resumable token, and no token can name the owner, so signing out returns a browser to its own visitor identity.
- The owner flag travels on entities (the crown), chat messages (badge) and presence (
presence.owner.page). Withincognitoin hello, none of it is sent. - Moderation (
mod: delete a chat message, mute a visitor) is accepted only from sockets with the cookie.
- Display: a procedural gold crown above the name tag, plus a gold minimap marker. The header chip, the arrival toast (once per visit) and the chat badge all use the crown icon. The chip is compact ("Kenil"), and while it shows, the visitor's own callsign text makes room.
Consequences
- + No password exists, so none can be phished, reused or leaked. A stolen laptop still needs the device's PIN or biometrics.
- + One cookie serves both backends. A script injected into the page can't read it, and other sites can't send it.
- + Visitors can trust the crown: it is set only by the server, from a verified cookie.
- − Losing every passkey means running
admin:resetwith database access. That is acceptable for a single owner. - − A session ends at most 12 hours after sign-out on another device. Rotating
OWNER_SECRETends all sessions at once. - M6: put
OWNER_SECRETin SSM, shared by the API and the real-time server. CloudFront must forward thekp_ownercookie to/api/*and/rt. SetADMIN_ORIGIN=https://kenilgor.com.