spec rev 3: Astra round 2 (code MAC key in memory, cap never burns links)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2 files changed,
+55
−7
docs/superpowers/reviews/CODEX-FINDINGS-email-signin-r2.md+35 −0docs/superpowers/specs/2026-10-21-console-email-signin-design.md+20 −7
CI passed — run details
diff --git a/docs/superpowers/reviews/CODEX-FINDINGS-email-signin-r2.md b/docs/superpowers/reviews/CODEX-FINDINGS-email-signin-r2.md| new file mode 100644 |
| index 000000000..3d973db7a |
| --- /dev/null |
| +++ b/docs/superpowers/reviews/CODEX-FINDINGS-email-signin-r2.md |
| @@ -0,0 +1,35 @@ |
| +| Round-1 finding | Disposition | Rev-2 assessment | |
| +|---|---|---| |
| +| 1. Login CSRF | fixed | §5.1 requires a confirmation nonce and request-origin checks, including legacy confirmation. | |
| +| 2. Unlimited guessing budgets | fixed | §5 adds shared online guessing limits and creates no redeemable challenge for refused requests. | |
| +| 3. Pending-action hash mismatch | fixed | §6 specifies redemption by stored hash with the existing safeguards. | |
| +| 4. SMTP fallback to Keymail | fixed | §4 adopts the settled B4 classification; §11 applies that policy to notifications. | |
| +| 5. First CLI step-up email suppressed | fixed | §§5.3 and 7 implement B2: fresh email sign-in counts as step-up, with separate step-up send limits. | |
| +| 6. Challenge outlives pending action | fixed | §6 gives step-up challenges the pending action’s ten-minute lifetime. | |
| +| 7. Recipient validation | fixed | §11 requires normalized, strictly parsed bare addresses throughout. | |
| +| 8. `next` bypasses onboarding | fixed | §8 requires account selection or creation before following `next`. | |
| +| 9. Existing SES identity ownership | fixed | §9 explicitly requires the adoption check and ownership TXT record. | |
| + |
| +Reviewed spec rev 2 at `ac21aa3b`. These dispositions assess the design, not completed implementation. |
| + |
| +1. **P1 — Read-only challenge-table access permits offline code recovery and account takeover.** |
| + |
| + **Spec:** §5, particularly [the hash definition and database-read guarantee](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/email-signin/docs/superpowers/specs/2026-10-21-console-email-signin-design.md:143). |
| + |
| + **Evidence:** [server.go:2733](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/email-signin/internal/console/server.go:2733) takes the target address from an unauthenticated requester. Existing session hashes protect a 32-byte random secret generated at [store.go:2394](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/email-signin/internal/console/store.go:2394); the proposed code hash instead protects six digits using an ID known to that requester. |
| + |
| + **Failure:** An attacker requests a challenge for the victim and retains their own challenge cookie. With read-only access to the resulting database row, they enumerate `sha256(id || code)` offline, then submit the recovered code once. Neither online guessing limit helps. An in-memory reproduction recovered a sample code in under one second. This violates the explicit database-read guarantee without requiring mailbox access. |
| + |
| + **Fix:** Authenticate the code digest with a server secret stored outside the database, such as HMAC over the challenge ID and code. Retain the online limits. |
| + |
| +2. **P2 — The new guessing limit lets one browser invalidate another browser’s valid links.** |
| + |
| + **Spec:** [§5’s address-wide challenge deletion](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/email-signin/docs/superpowers/specs/2026-10-21-console-email-signin-design.md:167). |
| + |
| + **Evidence:** The request entry point at [server.go:2730](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/email-signin/internal/console/server.go:2730) requires no session or mailbox proof. The existing redemption precedent deletes only the presented token at [store.go:2486](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/email-signin/internal/console/store.go:2486); rev 2 explicitly expands deletion to every live sign-in challenge for the address. |
| + |
| + **Failure:** An attacker creates challenges for a victim in attacker-controlled browsers and exhausts the shared wrong-code budget. That burns a legitimate link already delivered to the victim’s separate browser, despite the attacker never possessing that link. Three challenge requests, spaced to respect the cooldown, suffice to exceed ten wrong guesses. |
| + |
| + **Fix:** Keep the shared code-verification limit, but preserve other browsers’ high-entropy links. Burn only the offending challenge; allow existing valid links to redeem while code verification is throttled. |
| + |
| +No files were edited. No repository test suites were run. |
| \ No newline at end of file |
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 0bbdb561e..0dc897ba1 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 |
| -Status: draft rev 2, 2026-10-21 (rev 1 + builder check + Astra round 1, §15). Follows |
| +Status: draft rev 3, 2026-10-21 (rev 1 + builder check + Astra rounds 1-2, §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. |
| @@ -140,7 +140,7 @@ authstore/step-up precedent, and classified in `claimSQLTables`): |
| email_challenges( |
| id_hash TEXT PRIMARY KEY, -- sha256 of the browser-held id |
| link_hash TEXT UNIQUE, -- sha256 of the emailed link token |
| - code_hash TEXT NOT NULL, -- sha256(id || code) |
| + code_mac TEXT NOT NULL, -- HMAC-SHA256(process key, id || code) |
| purpose TEXT NOT NULL, -- 'signin' | 'stepup' |
| address TEXT NOT NULL, |
| session_hash TEXT NOT NULL DEFAULT '', -- stepup: the session it serves |
| @@ -158,8 +158,14 @@ email_challenges( |
| - **The browser holds the id** in an HttpOnly cookie |
| (`carlos_console_email`, `Secure` on https, `SameSite=Lax`, 15 min). |
| Only hashes are stored, so a database read is not a sign-in. |
| -- **The code** is 6 digits from crypto/rand, hashed with the challenge id |
| - so a code table leak is not a list of codes. **5 wrong attempts** burn |
| +- **The code** is 6 digits from crypto/rand, stored as |
| + HMAC-SHA256 over (challenge id, code) under a **key held only in the |
| + console process's memory**, minted at start (codex r2-1). A plain hash |
| + would not do: six digits under an id the requester knows fall to an |
| + offline search in under a second, so a database read would be a |
| + sign-in. The cost is that a console restart invalidates codes in |
| + flight; links still work (they are 32 random bytes, hashed), and asking |
| + again sends a fresh code. **5 wrong attempts** burn |
| the challenge. A code is only ever checked against the challenge named |
| by this browser's cookie, so there is no global code space to guess in. |
| - **The link token** is 32 random bytes, base64url, the `randomToken` |
| @@ -167,9 +173,11 @@ email_challenges( |
| - **Guessing is bounded per address, not just per challenge** (codex 2). |
| A fresh challenge must not buy a fresh guessing budget. Wrong codes are |
| counted per address across all its challenges (10 per day) and per |
| - client IP (30 per hour); past either, every live sign-in challenge for |
| - that address is burned and further codes are refused until the window |
| - passes. A rate-limited request (§7) creates **no** challenge at all, |
| + client IP (30 per hour). Past either, code checks for that address (or |
| + from that IP) are refused until the window passes, and only the |
| + challenge the wrong code was entered against is burned. Other |
| + challenges' **links** keep working: they carry 32 random bytes and an |
| + attacker without the mailbox cannot have them (codex r2-2). A rate-limited request (§7) creates **no** challenge at all, |
| while rendering the same page, so refused requests are not redeemable |
| either. |
| - One live challenge per (browser, purpose): asking again replaces the |
| @@ -463,3 +471,8 @@ budget (§5); codex 3 pending-action hash (§6); codex 4 no SMTP to Keymail |
| (§4, §11); codex 5 CLI step-up cooldown (§5.3, §7); codex 6 step-up TTL |
| (§6); codex 7 strict address parsing (§11); codex 8 onboarding before |
| `next` (§8); codex 9 existing-identity proof (§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). |