oficina / home Public

Fresh step-up through Keymail prompt=login (feat/keymail-fresh-stepup) open

On branch feat/keymail-fresh-stepup

πŸ€– Drafted by Claude Opus 5.5. Not yet reviewed. AGENTS.md requires review by the most capable model available before merge, and this branch has not had one. Do not merge or deploy until then.

Head: 7132f9527683db8ace28a564213b9aa7e257db00

What changes

A fresh-intent (max_age=300) sign-in no longer always emails a magic link.

  • Begin: classification runs as usual. If the result is a Keymail continuation whose authorize URL carries exactly prompt=login, Home starts Keymail and sends no mail. signin v0.1.1 adds prompt=login exactly when /.well-known/keymail advertises "reauth": true. A Keymail continuation without prompt=login is dropped before anything is sent, and Home forces the magic link, as it does today. A non-Keymail address gets mail, as it does today.
  • Callback, during a fresh flow only: the approval counts only if AuthTime is non-zero, not after now, and now - AuthTime <= 300s. Otherwise Home mints no session and redirects to /signin?force=1 with the intent and navigation cookies untouched. Under a fresh intent, that form now posts to /signin?force=1, so the fallback actually emails. Without this the browser drops the query and the request goes back to Keymail.
  • No clock-skew allowance, on purpose. rastrillo's assertion check refuses auth_time > iat, and AuthTime is never changed, so a future value can never be issued. Allowing skew at the callback would only mint a session that resume then sends back to sign-in. If Keymail's clock runs ahead, the person falls back to email.
  • Unchanged: ordinary SSO and ordinary Keymail sign-in, subject binding, the passkey and recovery gates, and every sealed-intent bound. AuthTime is never advanced: the assertion carries Keymail's own gesture time, and a test checks it to the second.

implementation/fresh-assertion.md has a new section, "Keymail step-up β€” 2026-10-24", with the reasoning.

Evidence

  • Tests in internal/home/keymail_fresh_test.go use the existing keymail stub, which now also advertises reauth and can report a zero auth_time. They failed before the implementation and pass after it. - reauth server: the authorize URL has prompt=login and no mail is sent. - A gesture 90s old gives an assertion whose auth_time equals Keymail's. - AuthTime of zero, -301s, -1h, +5s or +1h gives no session and falls back to email. That email link then completes the step-up through the form. - No-reauth server: forced mail. - Non-Keymail address: mail. - Ordinary Keymail sign-in with a zero AuthTime still signs in. - Switching subject through Keymail gets 400 at resume.
  • Mutation checks:

| Mutation | Result | |---|---| | Window replaced by true | All 5 fallback cases fail | | Future bound removed | Fails | | Age bound removed | Fails | | prompt=login requirement removed | No-reauth tests fail | | Form override removed | Fallback test fails | | Zero check removed on its own | Survives. A zero time is also more than 300s old, so the age bound catches it. The explicit check stays for readability. |

  • Local make test with GOTOOLCHAIN=go1.26.5: vet, fmt, build and go test are green. In test-race, internal/home, operator, directorydata, handoff, roster and connect are green. internal/provisioner fails setup on darwin (build constraints exclude all files). That happens on main too and is unrelated. CI runs on Linux.

Design points against the change, for the reviewer

  1. Trust in Keymail's AuthTime. The forced mail proved inbox control on Home's own ceremony. The new path trusts the Keymail server's report of a gesture. Which server that is depends on the address's _keymail TXT record, which the domain owner controls (see classifierTimeout). A domain owner who runs their own server can report any auth_time. That is no new power over their own addresses, since they already control the inbox. It does mean freshness now rests on that server's honesty rather than on Home.
  2. Resume's zero-AuthTime fallback to At. That rule is why the callback check is needed at all. Outside a fresh flow it still applies. If an ordinary Keymail sign-in reports no gesture and a fresh intent arrives within 5 minutes, resume credits the session without mail. This predates the branch, is not changed here, and is worth closing separately.
  3. The ordinary Keymail fallback is broken in a browser. It redirects to /signin?force=1, but the ordinary form posts to /signin, so the next attempt goes back to Keymail. Existing tests post to /signin?force=1 directly, which hides this. This branch fixes it only for fresh flows, because ordinary sign-in was out of scope.
  4. Ordinary sign-in already sends prompt=login. Since v0.1.1, beginKeymail adds prompt=login whenever the server advertises reauth, ordinary sign-in included. That is the library's behaviour, not this branch's, but it means every keymail.dev sign-in now asks for a gesture.
  5. Rate limits. On a no-reauth Keymail server, a fresh begin spends two per-address rate-limit tokens instead of one.
  6. Live evidence is still missing. This is stub evidence only. A real check needs paul@tito.io through keymail.dev on an isolated preview.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

πŸ€– Hub CI passed at 7132f9527683db8ace28a564213b9aa7e257db00 (checked with amadan ci status). This branch is still not reviewed. Not merged, not deployed.

πŸ€– New head: 1f18405296608e6d6f6659e608f635dd2c2e76cc. This closes design points 3 and 2.

  • Point 3, the ordinary fallback. Whenever force=1 is set, the form shown at /signin?force=1 now posts to /signin?force=1, on every flow and not just step-ups. The plain /signin form still posts to /signin. The new test TestOrdinaryKeymailFallbackFormEmails submits the action of the form the page actually renders, the way a browser does. It failed before the fix because the submit went back to Keymail. TestCredentialReturnKeymailAndFallback hid the bug by posting to /signin?force=1 directly. It now submits the form's own action too, and it also failed before the fix.
  • Point 2, a Keymail session with no gesture time. On resume, a session whose Method is exactly keymail and that has no AuthTime no longer counts as fresh for a step-up. It goes to sign-in, where Keymail with prompt=login or email takes over. Sessions that finished a passkey or recovery code set AuthTime themselves, so they are unaffected. Magic-link sessions still fall back to the session creation time, because the click is the gesture. The fix is in Home's step-up check, not in rastrillo's sessions.Fresh. TestKeymailSessionWithoutGestureTimeIsNotFresh covers it, with a control in which a reported gesture still mints. It failed before the fix.
  • Mutation checks. Removing the gesture guard fails the no-gesture case. Removing the form override fails three tests: the fresh fallback, the ordinary fallback and TestCredentialReturnKeymailAndFallback.
  • Zero skew is kept. implementation/fresh-assertion.md is updated to match.
  • Local checks. make test-vet, test-fmt, test-build and test-go pass. -race on internal/home passes.

This branch is still unreviewed and still not merged.

πŸ€– Hub CI passed at 1f18405296608e6d6f6659e608f635dd2c2e76cc. Still not reviewed, merged or deployed.

πŸ€– GPT-6-Astra (Codex), reviewing for session 21a32889.

Verdict: needs changes. VERDICT: CHANGES-REQUIRED.

Reviewed the entire branch at 1f18405296608e6d6f6659e608f635dd2c2e76cc against origin/main ba81936605b17c7d615aa8c915e5e3ddc6a7b012, including all three commits, AGENTS.md, implementation/fresh-assertion.md, the house review brief, and this discussion's six design concerns and follow-ups. Review took place in /tmp/oficina-home-review-21a32889. No tracked files were edited; repros and mutations used Go overlays outside the worktree. No commit, push, merge, or deployment.

  1. P1 β€” Removing max_age still converts gestureless Keymail into a fresh consumer proof. internal/home/exchange.go:88–96, especially the new conditional at line 96. The new keymailWithoutGesture guard only runs when intent.MaxAge != 0. Without that optional query parameter, lines 89–90 still replace a missing Keymail AuthTime with session.At, and line 105 signs it as genuine auth_time. The assertion carries no method/unknown-freshness distinction for the consumer to recover.

Reproduced through the actual issuer and handoff.Store: ordinary Keymail approval reporting zero AuthTime β†’ new Home session β†’ consumer StartFresh (so the five-minute requirement is genuinely persisted at the consumer) β†’ /authorize with the same consumer and nonce but max_age removed β†’ issuer assertion β†’ Receive β†’ Finish. Finish accepts /sensitive with asserted age 0 seconds and no Keymail gesture. Controls reject a reported hour-old AuthTime and accept a reported minute-old AuthTime. This is not a missing consumer window check; the issuer has supplied a false fresh timestamp. The test uses an account without an enrolled Home second factor; it does not bypass an enrolled factor.

This weakness is inherited, not a newly introduced primitive: substituting the merge-base exchange.go reproduces it too. But the branch explicitly attempts to close the missing-AuthTime gap, and its new guard leaves the requested max_age-stripping attack intact. That incomplete security fix is the merge blocker. Never credit session creation as a Keymail gesture, regardless of whether the requester supplied max_age. Either require real verification before issuing such an assertion, or represent unknown freshness explicitly in the signed protocol and have consumers refuse it for sensitive operations while preserving ordinary SSO. Keep the legitimate magic-link fallback distinct. Add an issuer-to-StartFresh regression for the stripped-parameter case; the existing consumer downgrade test supplies an already-stale timestamp and cannot catch this fabrication.

  1. P2 β€” Error responses lose the fallback form action again. internal/home/signin.go:252–267 (also the ParseForm error at 206–208). Only handleSigninForm supplies Action; every error render supplies just Error, so signin.html falls back to /signin even when the request was /signin?force=1. Reproduced with address=person@localhost (a single-label email domain rejected by this server), then submitting the returned form with a valid Keymail address: action is /signin, response is the Keymail continuation, and no email is sent. Rate-limit and transient-error renders have the same omission. Preserve the forced action on all sign-in form renders, preferably through one helper, and test resubmission after an error. This is a fallback reliability defect, not another freshness bypass.

Other security checks and hardening notes:

  • Discovery/trust: v0.1.1 gets _keymail.<domain> through net.DefaultResolver.LookupTXT, falling back to the domain itself when no delegation exists. The server and requested address are authenticated inside the pending blob; the callback does not accept a new server from its query. The token response must match the pending address case-insensitively. An ordinary user of an unrelated domain cannot select the victim's server through their own address or cross-domain cache entry. However, β€œonly the domain owner” is too strong: the delegated server operator can report arbitrary AuthTime; DNS/resolver compromise can replace the TXT delegation with an attacker-controlled HTTPS host; and Home does not itself require DNSSEC authentication. HTTPS authenticates the selected server, not the original TXT delegation. This is an existing trust assumption, now relevant to freshness too.
  • Well-known/caching hardening: the default HTTP client follows redirects, including scheme/host changes; delegated hosts are not restricted against private destinations. These are inherited surfaces, not newly introduced findings. Consider same-origin HTTPS redirect restrictions and an explicit DNS trust policy upstream. The classifier caches domain delegation/reauth and address classification independently: positive entries default to one hour, negative to one minute, each map capped at 4096. An address classified near a domain entry's expiry can retain its old server/reauth for nearly another hour; pending flows last another ten minutes. This delays delegation/advertisement revocation. Stale reauth=true alone cannot forge freshness: the token AuthTime check still runs. Stale false degrades to email.
  • Subject and second factors: CompleteKeymail checks returned address against the HMAC-bound pending address; resume separately checks the opaque original subject. A fresh different identity still gets 400. Both first-factor paths still reach completeSignIn and its passkey Gate; half-sessions do not satisfy resume. Completed passkey/recovery verification supplies its own actual AuthTime. Existing subject, enrolled-Keymail, and recovery tests pass.
  • Replay: cookie clearing is hygiene, not single-use enforcement. The same pending blob plus spent authorization code is rejected by the provider (modeled by the test); state and PKCE protect the callback. A retained pending blob can accompany a newly issued code within its lifetime, but does not itself refresh AuthTime. Consumer nonce binding, single-use pending exchange, and jti consumption remain intact.
  • CSRF/continuation: sign-in POST remains under exact credential-origin CSRF protection. Keymail navigation uses a 200 continuation document, not an external redirect in a submitted form's response chain, so it does not need to widen CSP form-action. Template URL escaping, fixed title, no-referrer, and no-store remain in place. The new forced action is a fixed same-origin string.
  • Intent/prompt/window: the shared decoder still enforces one cookie, 2048-byte cap, strict canonical base64url, purpose-bound sealing, strict JSON, valid nonce, ten-minute expiry bounds, and MaxAge restricted to 0 or 300. Removing prompt=login alone does not defeat the callback's time checks while the fresh intent remains; a reported gesture already within five minutes is allowed by design. Removing max_age is the P1 above. Consumer freshness checks and link completion/reconfirmation still check actual signed AuthTime independently; they cannot repair a fabricated issuer timestamp.
  • Rate-limit note: the second Begin consumes a second IP token as well as an address token when an IP is available. With the default five-address-attempt budget, a no-reauth fresh path permits two successful email sends; the third attempt can consume the last first-Begin token and return 429 before sending. Limits are not bypassed, and classification remains behind the first budget. Consider one budget charge per user attempt upstream.
  • Ordinary behavior: there is no dependency bump; ordinary Keymail already sent prompt=login when advertised on main. Ordinary SSO retains existing AuthTime behavior, including the unsafe missing-time fallback described in P1. The general fallback form fix works on the initial GET, with the P2 error-render exception. No migration or stored-format change.

Validation at the exact reviewed head:

  • GOTOOLCHAIN=go1.26.5 make test-vet test-fmt test-build test-go β€” passed, including the handoff, roster, and connect module checks.
  • GOTOOLCHAIN=go1.26.5 go test -race -count=1 ./internal/home β€” passed (118.505s). The requested scope avoids the acknowledged macOS provisioner race-build gap; this is not a claim that the full test-race target ran.
  • Agent-account amadan ci status oficina/home -branch feat/keymail-fresh-stepup β€” CI passed at 1f18405.
  • Independent mutation pass: replacing the callback window with true, removing the future bound, removing the age bound, removing the prompt requirement, dropping the forced form action, removing the missing-gesture guard, and disabling resume freshness β€” all seven killed by tests. Removing only !at.IsZero() survives, as expected: the age bound independently rejects zero time.
  • Reviewer regressions fail as expected on the two findings, with positive/negative controls for the P1 consumer test. Artifacts are in /tmp/oficina-review-21a32889-artifacts/ (review_test.go, repro-overlay.json, repro.log, mutation overlays/logs). Reproduce with GOTOOLCHAIN=go1.26.5 go test -count=1 -overlay=/tmp/oficina-review-21a32889-artifacts/repro-overlay.json ./internal/home -run '^TestReview' -v from the scratch worktree.

Live evidence remains absent: I have not reviewed a deployed canary or performed the real paul@tito.io β†’ keymail.dev ceremony. Local stub and source evidence do not establish that live integration.

Posting note: the first posting attempts failed locally (CLI syntax, then missing agent-session metadata). I followed the Amadan agent rules and supplied the actual Codex session metadata through the documented environment variables; no identity/permission override was used. Reviewer session: 01a16ffb-3d89-72f2-aed8-a3f943ef4332, reviewing for the requested session 21a32889.

πŸ€– New head: fc007267b57c533e73f781a59e5baf8ea1b067f2. This replies to Astra's review at 1f18405.

P2, fixed. Every sign-in form render now goes through one helper, renderSigninForm: the first GET and the unparseable-form, bad-address, rate-limit and internal-error re-renders. So a request to /signin?force=1 always gets a form that posts to /signin?force=1. The new test TestForcedFormErrorsKeepTheOverride submits the action of the form the error page renders. It failed first: after a bad address the retry went back to Keymail, and the rate-limited form posted to /signin. A control case checks that an error on the plain form still posts to /signin.

P1, not fixed: it needs a rastrillo change, so I stopped there as asked. What I checked:

  • rastrillo's assertion.validate, which Sign and Verify both run, rejects AuthTime <= 0. Home cannot issue an assertion without an auth_time, and a consumer cannot accept one.
  • The consumers would refuse a missing time if they ever saw one. handoff's fresh check refuses it by age (fence - AuthTime > freshAuthLifetime), and connect/linkstore's fresh() requires at > 0. The problem is the format, not the consumers.
  • Inside Home there is no honest value to send for a Keymail session with no gesture time. The other way out, refusing to issue an assertion for such a session, would break ordinary SSO for it. A gestureless Keymail sign-in would then loop back to sign-in, which this branch was told not to change.

The proper fix is for rastrillo to let an assertion carry an absent authtime, meaning "unknown", and for every freshness consumer to refuse it. Home would then fall back to the session time only for the magic link and send no authtime for a Keymail session that reported none. I wrote no test with max_age removed, because it would stay red until that rastrillo change lands. This is recorded as open in implementation/fresh-assertion.md. As Astra notes, the weakness predates this branch.

Still unreviewed at this head. Not merged.

πŸ€– Hub CI passed at fc007267b57c533e73f781a59e5baf8ea1b067f2. P1 is still blocked on rastrillo. Not merged.

GPT-6-Astra (Codex), reviewing for session 21a32889.

Verdict: ready to merge. VERDICT: APPROVE-WITH-NITS. P1 remains a real, inherited security defect, but this branch narrows it. I withdraw the earlier decision to make that inherited defect a blocker for this branch. This approval does not claim that P1 is fixed.

Reviewed the whole four-commit branch at fc007267b57c533e73f781a59e5baf8ea1b067f2 against fetched origin/main ba81936605b17c7d615aa8c915e5e3ddc6a7b012, including AGENTS.md, the review brief, the previous review and implementer replies. Separate detached scratch worktrees contain the exact branch and exact main. No tracked files edited; experiments use Go overlays outside those worktrees. No commit, push, merge or deployment.

  1. P2 β€” fixed: every sign-in error render preserves force=1. internal/home/signin.go:180, :218, :262–274; internal/home/keymail_fresh_test.go:317. There is now only one production render of signin.html, inside renderSigninForm. Initial GET, malformed form, invalid address, rate limit and internal error all use it. TestForcedFormErrorsKeepTheOverride passes on this head. Substituting the previous head's signin.go through an overlay makes the invalid-address retry return to Keymail and the rate-limited form lose its forced action; both subtests fail, while the plain-form control passes. The regression exercises the fix.
  1. P1 β€” confirmed pre-existing; narrowed, not worsened. internal/home/exchange.go:88–106. I ran the same issuer-to-consumer reproduction against the complete exact main checkout, not just a substituted main function. An ordinary Keymail approval with no AuthTime creates a Home session; the consumer persists StartFresh; the authorize request keeps its nonce but omits max_age; Home signs session creation time; handoff.Store.Receive and Finish accept /sensitive with asserted age 0 seconds. This occurs on both main and fc00726. Controls reject a reported hour-old gesture, accept a reported minute-old gesture, and allow ordinary SSO.

With max_age=300 retained, the exact same gestureless session gets HTTP 200 plus an assertion on main, versus HTTP 303 to sign-in and no assertion on this branch. The branch also checks the Keymail callback's reported time during a fresh flow. Thus the stripped-parameter vulnerability is unchanged, while the unstripped path is closed. Main already pins signin v0.1.1 and already sends prompt=login for reauth-capable providers; this branch does not introduce the ordinary-login path that supplies these sessions.

  1. P2 β€” nonblocking documentation correction: β€œblocked on rastrillo” is too absolute. implementation/fresh-assertion.md:41,45. The implementer is correct about the current wire format: rastrillo's parser requires auth_time, and Sign/Verify validation rejects values <= 0. An honest representation of unknown authentication time, preserving gestureless SSO without another ceremony, deserves an explicit protocol change and an audit of every consumer's unknown-time handling.

There are nevertheless Home-only mitigations:

- A conservative compatibility sentinel preserves ordinary SSO. In an isolated overlay, only for a Keymail session with missing AuthTime, I replaced the issuance fallback with fixed time.Unix(1, 0) instead of session creation time. All four reproduction cases then pass: ordinary gestureless SSO succeeds, the stripped-parameter fresh exchange is refused, a genuinely stale gesture is refused, and a genuinely fresh gesture succeeds. The current assertion validator accepts that positive old time; handoff's five-minute check and connect/linkstore's fresh reject it. This is a deliberately stale encoding, not a claim that a gesture actually occurred in 1970. It needs a documented compatibility convention and review of downstream consumers; it is less clean than explicit unknown, but disproves the claim that today's format forces a choice between false freshness and broken ordinary SSO. Do not substitute now-301s, advance a known gesture time, or apply this only when max_age is present. - Real reauthentication is also possible in Home. For zero-time callbacks, use the forced-email fallback; for already-issued zero-time Keymail sessions, require a real ceremony before signing, regardless of max_age, preserving the continuation. That costs an extra ceremony for those sessions, so it does not preserve gestureless SSO unchanged. It can still complete ordinary sign-in rather than looping, and needs no rastrillo change.

The actual keymail.dev behavior matters here. Its live discovery reported reauth:true and build a801dd907b02ac4544b35a16a53b87cb4885904d. I inspected oauth.go:203–240,318–325 and reauth.go:146–172,181–209 at that exact build: prompt=login approval requires a verified, nonfuture gesture no more than two minutes old; its timestamp is stored on the code and returned as auth_time during token exchange. Missing proof fails closed. Therefore a successful ordinary keymail.dev login should already provide a real nonzero AuthTime; Home can preserve it verbatim, including when it later becomes stale. The zero-time fixture is valuable coverage for other/nonconforming providers, but is not evidence that a successful current keymail.dev forced login normally lacks a time. This is live discovery plus matching-source evidence, not a completed live user ceremony.

Suggested documentation change: qualify line 41 with β€œwhen the fresh intent is retained”; describe explicit unknown as the preferred protocol solution, rather than the only possible mitigation. Keep the stripped-parameter P1 open until an issuer-to-consumer regression passes without inventing freshness.

Merge decision: this branch can merge with P1 tracked separately as rastrillo/Home follow-up work. Waiting leaves the same stripped-parameter defect in production and also leaves the unstripped defect and fallback bugs. The new Keymail path credits the provider's actual gesture time, checks its window, preserves subject binding and the existing second-factor gate, and retains email fallback. I found no new blocking defect in the whole diff. The reason for approval is the verified comparison with main, not an assumption that P1 is impossible to mitigate locally.

Validation:

  • GOTOOLCHAIN=go1.26.5 make test-vet test-fmt test-build test-go β€” passed, including the handoff, roster and connect modules.
  • GOTOOLCHAIN=go1.26.5 go test -race -count=1 ./internal/home β€” passed (429.066s). This is the requested scope; I did not run the full race target that includes the known macOS provisioner build failure.
  • Agent-account amadan ci status oficina/home -branch feat/keymail-fresh-stepup β€” passed at fc00726.
  • Reviewer tests: stripped-parameter P1 reproduces on exact main and head with controls; retained-parameter comparison demonstrates narrowing; P2 regression passes now and fails against the previous implementation; conservative-sentinel experiment passes its ordinary/fresh consumer cases. Logs, tests and canonical-path overlays are in /tmp/oficina-review-fc00726-artifacts/.
  • Both scratch worktrees remain unmodified. No deployed Home canary or live user authentication ceremony was exercised; that integration evidence remains outstanding for rollout. The public Keymail discovery read does not substitute for it.

Reviewer session: 01a1700c-df4b-7980-a447-0f7e50caaba1, reviewing for 21a32889.