spec rev 4: one door, Keymail discovered from the address (R5)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 file changed,
+120
−92
docs/superpowers/specs/2026-10-21-console-email-signin-design.md+120 −92
CI passed — run details
diff --git a/docs/superpowers/specs/2026-10-21-console-email-signin-design.md b/docs/superpowers/specs/2026-10-21-console-email-signin-design.md| index 0dc897ba1..978d14bd2 100644 |
| --- a/docs/superpowers/specs/2026-10-21-console-email-signin-design.md |
| +++ b/docs/superpowers/specs/2026-10-21-console-email-signin-design.md |
| @@ -1,6 +1,6 @@ |
| -# Console email sign-in (magic links), with Keymail as the alternative |
| +# Console email sign-in (magic links), with Keymail found from the address |
| -Status: draft rev 3, 2026-10-21 (rev 1 + builder check + Astra rounds 1-2, §15). Follows |
| +Status: draft rev 4, 2026-10-21 (rev 3 + R5: one door, Keymail discovered from the address; §15). Follows |
| [console invite delivery](2026-09-28-console-invite-delivery-design.md), |
| whose §4 console mailer this reuses and whose line 4 named this spec. |
| @@ -15,8 +15,9 @@ that is the front door shut to almost everyone. |
| Success: a person with any email address can sign up and sign in to the |
| console with a link sent to that address; an owner can invite any email |
| address and the invitee can accept; `carlos auth login` and every |
| -re-confirmed action work for that person; Keymail users carry on exactly |
| -as today. |
| +re-confirmed action work for that person; Keymail users type their |
| +address into the same field and land in Keymail's own sign-in, as they |
| +do today from the button. |
| ## 2. Rulings (Paul, 2026-10-21) |
| @@ -39,12 +40,18 @@ as today. |
| is the security ruling the invite-delivery rollout was waiting on for |
| the `ses:SendEmail` grant (`console_mail_from` / `console_mail_region`). |
| Roll order stays dev first, then flagship. |
| +- **R5. One door; Keymail is discovered, not chosen.** There is no |
| + separate "Sign in with Keymail" action. The person types their address; |
| + if it is a Keymail address (paul@keymail.dev) the console sends them |
| + straight into Keymail's OAuth ceremony, and otherwise it emails a link |
| + and code. |
| ## 3. Goals, non-goals, anti-goals |
| Goals |
| -- Email magic-link sign-in and sign-up on the console's front page, with |
| - "Sign in with Keymail" kept beside it. |
| +- One email field on the console's front page. A Keymail address goes to |
| + Keymail's sign-in; any other address gets a magic link and code, which |
| + sign up a new person and sign in a returning one. |
| - A code in the same email, so a link opened on a phone can still finish |
| a sign-in started on a laptop. |
| - Re-confirmation (step-up) by email link or code for email sessions. |
| @@ -58,9 +65,10 @@ Non-goals |
| - CAPTCHA or bot scoring. Rate limits only. |
| - Linking two addresses into one person. The address is the identity, as |
| today. |
| -- Changing the Keymail OAuth flow, Keymail step-up, or the existing |
| - Keymail Apps-inbox confirmation link beyond routing it through the new |
| - sender. |
| +- Changing the Keymail OAuth flow or Keymail step-up. (The old |
| + Apps-inbox confirmation link is retired, §11.) |
| +- A login hint to Keymail. Keymail has none; whoever authenticates there |
| + is who signs in, as today. |
| - Tito's console (blocked on the store boundary; it picks this up with |
| its next release like any other deployment). |
| @@ -69,7 +77,10 @@ Anti-goals (a failure even if it works) |
| able to re-confirm by email instead of its passkey. A stolen Keymail |
| session gains nothing from this feature. |
| - **An oracle.** The front page must not reveal whether an address has an |
| - account, a Keymail mailbox, or was rate-limited. |
| + account here or was rate-limited. (Whether an address is a Keymail |
| + mailbox is already public through Keymail's own lookup, so being sent |
| + to Keymail reveals nothing new. Discovery must therefore use only that |
| + public answer, never console state such as a stored grant.) |
| - **A mail cannon.** Nobody can make the console send more than a handful |
| of messages to an address they do not control. |
| - **Link scanners burning links.** Corporate mail scanners fetch every |
| @@ -78,55 +89,66 @@ Anti-goals (a failure even if it works) |
| screens unknown senders, so Keymail mailboxes are reached through |
| Keymail, never through SES. |
| -## 4. How a link reaches the person |
| - |
| -One sender, `signinSender`, used for sign-in links and for step-up links. |
| -It reuses the invite chain's order and its rules, minus the owner-visible |
| -fallback link: |
| - |
| -1. **The address has a stored Keymail grant** (`store.GrantToken` non-empty): |
| - `SendApp` into its Keymail Apps inbox. This is what `/auth/continue` |
| - does today. |
| -2. **Otherwise, Keymail federation** (`sendFederated`, as |
| - `console@<origin host>`). `IsKeymailBlocked` stops here: the person |
| - blocked the console, and email to the same address would go round |
| - them. `ErrNoKeymailMailbox` moves on. |
| -3. **Otherwise, the console mailer** (`ConsoleMailer.Send`, SES). |
| -4. Nothing worked: log it. The person sees the same page they would have |
| - seen on success (anti-oracle); the page says what to do if nothing |
| - arrives. |
| - |
| -A send that fails at step 1 with a dead grant (401) falls through to |
| -step 2, as a revoked grant is not a refusal. |
| - |
| -**When federation may fall through to SES.** Today `SendFederated` wraps |
| -every lookup error as `ErrNoKeymailMailbox`, so a Keymail outage would |
| -send `@keymail.dev` addresses to SES. The lookup answers definitively |
| -(checked live 2026-10-21): 400 "could not determine target mailbox" for a |
| -domain Keymail does not serve, 404 "no such mailbox" for an unknown local |
| -part, 409 "inbox not yet claimed". Only those three mean "no Keymail |
| -mailbox". A timeout, network error or 5xx is "Keymail unreachable": the |
| -sender stops there when the address's domain is the configured Keymail |
| -host (`CONSOLE_KEYMAIL`'s host) or the address has a stored grant, and |
| -otherwise falls through to SES (a non-Keymail domain should not lose |
| -sign-in because Keymail is down). `ErrFederationPriceTooHigh` and a |
| -delivery failure after a successful lookup stop: the address IS a Keymail |
| -mailbox. The invite chain takes the same rule. |
| - |
| -**The channel decides the session's method** (§5.4): a challenge whose |
| -link went out through steps 1 or 2 is recorded `via=keymail`; through |
| -step 3, `via=email`. The challenge row stores which (builder: a column, |
| -written by the background send before it hands the message over; a |
| -challenge with no recorded channel cannot be consumed). |
| +## 4. One door: discovery, then delivery |
| + |
| +### 4.1 Discovery (R5) |
| + |
| +`POST /auth/continue` takes `address` (validated per §11) and decides: |
| + |
| +1. The domain is the configured Keymail host (`CONSOLE_KEYMAIL`'s host, |
| + e.g. keymail.dev): **Keymail**. |
| +2. Otherwise ask Keymail's public federation lookup (new |
| + `Keymail.HasMailbox(ctx, addr) (bool, error)`, the same |
| + `/api/federation/lookup` call `SendFederated` makes, 5 s timeout): |
| + - 200: **Keymail** (a Keymail-served custom domain). |
| + - 400 "could not determine target mailbox", 404 "no such mailbox", |
| + 409 "inbox not yet claimed" (checked live 2026-10-21): **email**. |
| + - timeout, network error, 5xx: **email** (a non-Keymail-host domain |
| + should not lose sign-in because Keymail is down). |
| + |
| +Only public answers decide (anti-oracle): never a stored grant or any |
| +other console state. |
| + |
| +**Keymail** means exactly what `GET /auth/signin` does today (state and |
| +PKCE cookie, redirect to `AuthorizeURL`), plus the `next` cookie of §8. |
| +The session it makes is `method=keymail`. Whoever authenticates at |
| +Keymail is who signs in, even if they typed a different address. |
| + |
| +**Email** means a challenge (§5) and an emailed link and code (§4.2). |
| + |
| +`GET /auth/signin` stays as the ceremony's entry (the redirect target, |
| +and old bookmarks) but nothing on the page links to it any more. |
| + |
| +### 4.2 How a sign-in or step-up message is sent |
| + |
| +Only to addresses discovery called **email**, so only by the console |
| +mailer (`ConsoleMailer.Send`, SES). Never by SES to a Keymail-host |
| +address (anti-goal); discovery has already routed those to Keymail. |
| + |
| +**No console mailer** (none configured, or not yet verified): the front |
| +page says so plainly for an email-bound address ("this console can't |
| +send email yet") instead of pretending a message is on its way. This |
| +reveals only that the address is not a Keymail mailbox, which is public. |
| +A rate-limited request still gets the normal page. |
| **Sends run off the request.** The handler records the challenge, starts |
| -the send on a background goroutine with its own bounded context |
| -(20 s total, Keymail's share 12 s, the invite numbers), and renders the |
| -"check your email" page at once. This removes the timing oracle (a |
| -federation lookup takes visibly longer than a grant send) and keeps a |
| -slow PoW off the request. A process-wide semaphore (builder's call on the |
| -size; 4 is fine) bounds concurrent sends; a send that cannot get a slot |
| -within its context is dropped and logged. |
| +the send on a background goroutine with its own bounded context (20 s), |
| +and renders the "check your email" page at once, so send latency is no |
| +oracle. A process-wide semaphore (builder's call on the size; 4 is fine) |
| +bounds concurrent sends; a send that cannot get a slot within its |
| +context is dropped and logged. |
| + |
| +### 4.3 Invites and notices keep the two-channel sender |
| + |
| +Invites (existing chain) and the notices of §11 go to addresses the |
| +person did not just type, so they keep federation first, then SES, with |
| +this fall-through rule: today `SendFederated` wraps every lookup error |
| +as `ErrNoKeymailMailbox`. Only the definitive 400/404/409 answers mean |
| +"no Keymail mailbox" and may fall through to SES. A timeout, network |
| +error or 5xx stops when the domain is the Keymail host, and otherwise |
| +falls through. `ErrFederationPriceTooHigh`, `IsKeymailBlocked`, and a |
| +delivery failure after a successful lookup all stop: the address IS a |
| +Keymail mailbox. |
| ## 5. The challenge |
| @@ -205,7 +227,6 @@ auto-submit it from their own page into a victim's browser. So: |
| - every pre-session POST in this feature (`/auth/continue`, the link POST, |
| the code POSTs) also refuses a request whose `Origin` (or, when absent, |
| `Sec-Fetch-Site`) names another site. Absent both, allow (old clients). |
| -- the legacy `/auth/confirm` gets the same confirm-page-plus-nonce shape. |
| The code POST is already browser-bound through the challenge cookie, |
| which a cross-site POST does not carry. |
| @@ -225,23 +246,20 @@ welcome cookie when created, then `next` if set and safe, else |
| `redirectToCurrentAccount`. No grant token is stored for an email sign-in |
| (it has none), and an existing grant is left alone. |
| -**A link or code sign-in whose session method is `email` also records a |
| -step-up** (`RecordStepUp` at the moment of use). It is the same proof a |
| -step-up would ask for, minutes later, of the same mailbox; without it a |
| -signed-out `carlos auth login` sends two emails back to back. A |
| -`keymail`-method session from a link does not (it re-confirms with the |
| -passkey, as the old Apps-inbox link's sessions do). |
| +**A link or code sign-in also records a step-up** (`RecordStepUp` at the |
| +moment of use). It is the same proof a step-up would ask for, minutes |
| +later, of the same mailbox; without it a signed-out `carlos auth login` |
| +sends two emails back to back. |
| ### 5.4 The session remembers how it was proved |
| `sessions` gains `method TEXT NOT NULL DEFAULT 'keymail'`. Existing rows |
| read as `keymail`, which is true of every session today (the |
| Apps-inbox confirmation link is a Keymail channel and stays `keymail`). |
| -A session made by §5.1 or §5.2 takes its challenge's channel (§4): a |
| -link delivered through Keymail makes a `keymail` session, one delivered |
| -by SES an `email` session. So a Keymail user who types their address |
| -into the email form still re-confirms with their passkey. `session(r)` |
| -(or a sibling) exposes the method. |
| +A session made by §5.1 or §5.2 is `email`; a Keymail callback's is |
| +`keymail`. Discovery sends Keymail addresses to Keymail, so a Keymail |
| +user always re-confirms with their passkey. `session(r)` (or a sibling) |
| +exposes the method. |
| ## 6. Re-confirmation (R1) |
| @@ -251,7 +269,7 @@ into the email form still re-confirms with their passkey. `session(r)` |
| cannot do it. No email path. (Anti-goal: no downgrade.) |
| - **`email`**: stash the pending action exactly as today |
| (`StashPendingAction`), create a `stepup` challenge bound to this |
| - session hash and that pending token, send it through `signinSender`, |
| + session hash and that pending token, send it by the console mailer (§4.2), |
| and render a "check your email" page with a code box. |
| - `GET /auth/email/link?t=` for a stepup challenge renders a confirm |
| page; `POST` requires a session cookie whose hash equals the |
| @@ -289,7 +307,7 @@ numbers (builder may tune within reason): |
| | Key | Limit | |
| | --- | --- | |
| | per address, any purpose | 1 per 60 s, 5 per hour, 20 per day | |
| -| per client IP (`s.clientIP`, edge-proof aware) | 10 per hour | |
| +| per client IP (`s.clientIP`, edge-proof aware) | 10 emails per hour; 30 `/auth/continue` submissions per hour of any outcome (each one may cost a Keymail lookup) | |
| | whole console | 200 per hour | |
| Step-up challenges have their own per-address window (1 per 60 s, |
| @@ -308,7 +326,8 @@ lose their place. Two of them matter for this feature: |
| - `GET /invite/{token}` signed out: render the front page with the |
| invited address pre-filled ("Sign in as x@y to accept"), and `next` set |
| - to the invite page. Keymail's button carries the same `next`. |
| + to the invite page (carried as a hidden field into `/auth/continue`, so |
| + either discovery outcome gets it). |
| - `GET /auth/cli` signed out: `next=/auth/cli` (so a CLI user can sign in |
| and land on the code entry). |
| @@ -367,15 +386,10 @@ builder may make (`CARLOS_CONSOLE_NAME`, default "CARLOS platform"). |
| ## 10. Front page and copy |
| -- Home: an email field and "Email me a sign-in link" as the primary |
| - action; "Sign in with Keymail" as a second button below it. A console |
| - with no console mailer configured still shows the email form, because |
| - Keymail addresses are reached through Keymail; the page copy must not |
| - promise plain email will arrive when no mailer exists (builder: a |
| - `page` flag). |
| +- Home: one email field and one button. No Keymail button (R5). |
| - "Check your email" page (replaces `check.html`'s Keymail-only text): |
| - where it was sent, the code box, "nothing arriving?" advice, and the |
| - Keymail button. |
| + where it was sent, the code box, "nothing arriving?" advice. |
| +- The "this console can't send email yet" refusal (§4.2). |
| - Link confirm page, step-up "check your email" page, the three email |
| bodies (sign-in, step-up, invite), the invite page's signed-out |
| variant, the `team.html` invite copy (still says "the platform never |
| @@ -391,18 +405,21 @@ builder may make (`CARLOS_CONSOLE_NAME`, default "CARLOS platform"). |
| (federation, then SES under the same fall-through rule), never |
| straight to SES (codex 4). Operator alerts stay Keymail-only |
| (operators are Keymail users). |
| -- `handleContinue` (`POST /auth/continue`): becomes the email form's |
| - target (it already takes `address`), so no new route is needed for |
| - "request a link". The empty-address → `/auth/signin` redirect stays. |
| +- `handleContinue` (`POST /auth/continue`): becomes the form's target |
| + and runs discovery (§4.1). Its old body (an Apps-inbox confirmation |
| + link for addresses with a stored grant) goes. An empty address |
| + re-renders the front page with the bad-address error. |
| It validates with the invite handler's rule (codex 7): lower-case, |
| trim, `ValidAddress`, and `netmail.ParseAddress(addr).Address == addr`, |
| so `a<victim@example.com>` and list forms are refused before any |
| challenge, rate-limit key or user row exists. That one canonical |
| string is used everywhere after. |
| -- `handleConfirm` (`/auth/confirm?token=`, the old Apps-inbox link) keeps |
| - working for links already sent; new sign-in links use §5.1. It must |
| - stop signing in on GET (§3 anti-goal); give it the same confirm-page |
| - shape. |
| +- `handleConfirm` (`/auth/confirm?token=`, the old Apps-inbox link) is |
| + retired: nothing mints those links any more, and any already sent |
| + lapse within 15 minutes of the roll. The route stays (claim-routes) and |
| + renders the existing "link expired" message; `CreateConfirmation`'s |
| + last caller goes (leave the table; `PurgeExpired` keeps clearing it). |
| +- The "Check your Keymail" template and `page.KeymailURL` go. |
| - `PurgeExpired` also clears expired `email_challenges`. |
| - New routes go into `testdata/claim-routes.txt`, the invariant fixtures |
| and probes, like every route. |
| @@ -418,9 +435,14 @@ controllable clock): |
| - Link GET does not consume; POST does; second POST fails. |
| - Code: right code signs in; 5 wrong codes burn; a code from another |
| browser's challenge does not work. |
| -- Delivery order: grant → SendApp; no grant, Keymail mailbox → federation; |
| - `ErrNoKeymailMailbox` → console mailer; blocked → nothing sent; the |
| - page is byte-identical in every case, including rate-limited. |
| +- Discovery: Keymail-host address → redirect to Keymail with the state |
| + cookie; lookup 200 → Keymail; 400/404/409 → email; lookup timeout → |
| + email; a stored grant for a 404 address still → email (no console |
| + state in discovery). |
| +- The "check your email" page is byte-identical for a new address, a |
| + known one, and a rate-limited one. |
| +- Invite and notice chain: definitive no-mailbox → SES; lookup 5xx on a |
| + Keymail-host address → nothing sent; blocked → nothing sent. |
| - Rate limits at each key; a refused request creates no challenge. |
| - Guessing: wrong codes across several fresh challenges for one address |
| stop at the per-address cap (codex 2). |
| @@ -457,8 +479,8 @@ within the same order of magnitude; template structure. |
| ## 15. Review dispositions |
| Builder check (rev 1), settled as builder's calls: |
| -- B1 Keymail users via the email form: the delivery channel sets the |
| - session method (§4, §5.4). |
| +- B1 superseded by R5: Keymail addresses never get an email link, so the |
| + sign-in door sets the session method (§4.1, §5.4). |
| - B2 email sign-in counts as a step-up (§5.3); step-up has its own |
| per-address window (§7). |
| - B3 carloku.com refused: fall back to `noreply@mail.carloku.com` (§9). |
| @@ -476,3 +498,9 @@ Astra round 2 (`CODEX-FINDINGS-email-signin-r2.md`): all nine round-1 |
| fixes confirmed. Both new findings accepted: r2-1 codes MACed under an |
| in-memory key (§5); r2-2 the guessing cap throttles codes but never burns |
| another browser's link (§5). |
| + |
| +Rev 4 (Paul, 2026-10-21, R5): no "Sign in with Keymail" action; discovery |
| +from the address picks Keymail OAuth or email. Consequences: sign-in and |
| +step-up messages go by SES only (§4.2); the Apps-inbox confirmation link |
| +is retired (§11); B1's channel-based method is gone; invites and notices |
| +keep the B4 two-channel rule (§4.3). |