Home: every sign-in form render keeps the force override
The bad-address, rate-limit, unparseable-form and internal-error renders drew the form with action /signin even when the request was /signin?force=1, so the retry went back to Keymail (Astra review of #83, P2). One helper now draws the form for the first GET and every error. fresh-assertion.md records P1 as open and blocked on rastrillo: an assertion cannot carry an absent auth_time, so Home cannot stop crediting a gestureless Keymail session's At when max_age is stripped.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
3 files changed,
+58
−9
implementation/fresh-assertion.md+4 −0internal/home/keymail_fresh_test.go+38 −0internal/home/signin.go+16 −9
CI passed — run details
diff --git a/implementation/fresh-assertion.md b/implementation/fresh-assertion.md| index 5478580..4b487c8 100644 |
| --- a/implementation/fresh-assertion.md |
| +++ b/implementation/fresh-assertion.md |
| @@ -39,3 +39,7 @@ Unchanged: ordinary SSO and ordinary Keymail sign-in, including whatever prompt |
| Acceptance (keymail_fresh_test.go, against the existing keymail stub with "reauth" added): fresh intent plus a reauth server gives an authorize URL with exactly prompt=login and no mail; a gesture 90 s old yields an assertion whose auth_time equals Keymail's; zero, 301 s, one hour, +5 s and +1 h AuthTime give no session and fall back to email, and that email link completes the step-up through the form a browser would submit; a server without reauth gets forced mail; a non-Keymail address gets mail; ordinary Keymail with zero AuthTime still signs in; subject switching through Keymail is refused. Mutation: replacing the window with true fails all five fallback cases, as do removing the future bound or the age bound alone; dropping the prompt=login requirement fails the no-reauth tests; dropping the form's override fails the fresh fallback, the ordinary fallback and TestCredentialReturnKeymailAndFallback. Removing only the zero check survives, because a zero time is also more than 300 s old; the explicit check stays as documentation of the case Keymail defines. |
| A Keymail session with no gesture time never satisfies a step-up. Resume refuses a session whose Method is exactly "keymail" and whose AuthTime is zero, even inside the window: sessions.Fresh would fall back to At, which is when Home minted the session, not anything the person did. The step-up then goes to sign-in, where the rules above apply (Keymail with prompt=login, or email). A completed second factor ("keymail+passkey", "keymail+recovery") sets AuthTime itself and is unaffected; magic-link sessions keep the At fallback, because the click is the gesture. Tested with a control (the same flow with a reported gesture mints) and mutation-checked: removing the guard fails the no-gesture case. |
| + |
| +Error re-renders (unparseable form, bad address, rate limit, internal error) draw the form through the same helper as the first GET, so a forced form keeps posting to /signin?force=1 after an error (TestForcedFormErrorsKeepTheOverride, failing first). |
| + |
| +Open, blocked on rastrillo (Astra review of #83 at 1f18405, P1): the guard above runs only when max_age is present. Without max_age, resume still substitutes session At for a Keymail session's missing AuthTime and signs it as auth_time, and a consumer that persisted its own five-minute requirement (handoff StartFresh) accepts it at age 0. The honest assertion for such a session carries no auth_time, which handoff's fresh check (age > freshAuthLifetime) and connect/linkstore's fresh() (at > 0) would both refuse. But rastrillo's assertion.validate, run by Sign and Verify alike, rejects AuthTime <= 0, so Home cannot issue one, and ordinary SSO for these sessions would break if it refused instead. Closing it needs rastrillo to let an assertion carry absent (unknown) auth_time, with every freshness consumer refusing that. Home then falls back to At only for the magic link. Not changed on this branch. |
diff --git a/internal/home/keymail_fresh_test.go b/internal/home/keymail_fresh_test.go| index 843d308..08dfc1e 100644 |
| --- a/internal/home/keymail_fresh_test.go |
| +++ b/internal/home/keymail_fresh_test.go |
| @@ -311,3 +311,41 @@ func TestKeymailSessionWithoutGestureTimeIsNotFresh(t *testing.T) { |
| }) |
| } |
| } |
| + |
| +// An error re-render of the form must keep the override too. Each of |
| +// these renders the form again, and the person resubmits that form: if |
| +// its action is plain /signin, the retry goes back to Keymail. |
| +func TestForcedFormErrorsKeepTheOverride(t *testing.T) { |
| + t.Run("bad address", func(t *testing.T) { |
| + app := newTestApp(t) |
| + newKeymailStub(t, app, freshKeymailAddress) |
| + bad := returnRequest(app, "POST", "/signin?force=1", url.Values{"address": {"person@localhost"}}) |
| + if bad.Code != 400 { |
| + t.Fatal("single-label domain accepted", bad.Code) |
| + } |
| + retry := returnRequest(app, "POST", formAction(t, bad), url.Values{"address": {freshKeymailAddress}}) |
| + if retry.Code != 303 || retry.Header().Get("Location") != "/signin/sent" { |
| + t.Fatal("retry after an error went back to Keymail", retry.Code) |
| + } |
| + }) |
| + t.Run("rate limited", func(t *testing.T) { |
| + app := newTestApp(t) |
| + var last *httptest.ResponseRecorder |
| + for range 6 { |
| + last = returnRequest(app, "POST", "/signin?force=1", url.Values{"address": {"person@example.invalid"}}) |
| + } |
| + if last.Code != 429 { |
| + t.Fatal("address budget not reached", last.Code) |
| + } |
| + if got := formAction(t, last); got != "/signin?force=1" { |
| + t.Fatalf("rate-limited form action=%q", got) |
| + } |
| + }) |
| + t.Run("plain stays plain", func(t *testing.T) { |
| + app := newTestApp(t) |
| + bad := returnRequest(app, "POST", "/signin", url.Values{"address": {"person@localhost"}}) |
| + if got := formAction(t, bad); got != "/signin" { |
| + t.Fatalf("plain error form action=%q", got) |
| + } |
| + }) |
| +} |
diff --git a/internal/home/signin.go b/internal/home/signin.go| index d73d14d..61ff83c 100644 |
| --- a/internal/home/signin.go |
| +++ b/internal/home/signin.go |
| @@ -170,11 +170,22 @@ func clientIP(r *http.Request) string { |
| // held to the same checks. |
| func (a *App) handleSigninForm(w http.ResponseWriter, r *http.Request) { |
| rememberReturn(w, r) |
| + a.renderSigninForm(w, r, http.StatusOK, "") |
| +} |
| + |
| +// renderSigninForm is the one way the address form is drawn: the first |
| +// GET and every error re-render alike. The person resubmits whatever |
| +// form is on screen, so an error page that dropped the override would |
| +// send a forced retry straight back to Keymail. |
| +func (a *App) renderSigninForm(w http.ResponseWriter, r *http.Request, status int, msg string) { |
| data := map[string]any{} |
| + if msg != "" { |
| + data["Error"] = msg |
| + } |
| if r.URL.Query().Get("force") == "1" { |
| data["Action"] = "/signin?force=1" |
| } |
| - a.render(w, r, http.StatusOK, "signin.html", data) |
| + a.render(w, r, status, "signin.html", data) |
| } |
| // handleSigninSent is the check-your-mail page. It is reached by |
| @@ -204,8 +215,7 @@ func againHref(r *http.Request) string { |
| // neither discloses whether that person has an account here. |
| func (a *App) handleSigninBegin(w http.ResponseWriter, r *http.Request) { |
| if err := r.ParseForm(); err != nil { |
| - a.render(w, r, http.StatusBadRequest, "signin.html", |
| - map[string]any{"Error": "That did not look like a form."}) |
| + a.renderSigninForm(w, r, http.StatusBadRequest, "That did not look like a form.") |
| return |
| } |
| address := strings.TrimSpace(r.PostFormValue("address")) |
| @@ -254,17 +264,14 @@ func (a *App) beginFailed(w http.ResponseWriter, r *http.Request, err error) boo |
| case err == nil: |
| return false |
| case errors.Is(err, signin.ErrBadAddress): |
| - a.render(w, r, http.StatusBadRequest, "signin.html", |
| - map[string]any{"Error": "That does not look like an email address."}) |
| + a.renderSigninForm(w, r, http.StatusBadRequest, "That does not look like an email address.") |
| case errors.Is(err, signin.ErrRateLimited): |
| // 429 without saying which budget: which one was hit is itself |
| // information about whether that address has been tried. |
| - a.render(w, r, http.StatusTooManyRequests, "signin.html", |
| - map[string]any{"Error": "Too many attempts. Try again shortly."}) |
| + a.renderSigninForm(w, r, http.StatusTooManyRequests, "Too many attempts. Try again shortly.") |
| default: |
| a.logger.Error("signin begin", "err", err) |
| - a.render(w, r, http.StatusInternalServerError, "signin.html", |
| - map[string]any{"Error": "Something went wrong. Try again."}) |
| + a.renderSigninForm(w, r, http.StatusInternalServerError, "Something went wrong. Try again.") |
| } |
| return true |
| } |