Oficina ID follow-ups: bounded receipts, zero-codes return, consumer API
Direct-passkey receipts no longer share a global refusal cap; the zero-codes detour keeps the return target (local paths only); handoff and linkstore expose transaction-owned operations for Equipo. Reviewed by Fable. Squashed from oficina-id-followups into main. Co-Authored-By: codex <codex~paul@keymail.dev>
10 files changed,
+285
−37
connect/linkstore/atomic_test.go+52 −0connect/linkstore/flows.go+96 −28handoff/atomic_test.go+42 −0handoff/store.go+34 −0internal/home/id_direct.go+0 −4internal/home/id_followups_test.go+49 −0internal/home/id_passkey.go+6 −1internal/home/id_review_test.go+2 −2internal/home/passkey.go+2 −2internal/home/templates/recovery_codes.html+2 −0
CI cancelled — superseded by a newer push — run details
diff --git a/connect/linkstore/atomic_test.go b/connect/linkstore/atomic_test.go| new file mode 100644 |
| index 0000000..fe2ecec |
| --- /dev/null |
| +++ b/connect/linkstore/atomic_test.go |
| @@ -0,0 +1,52 @@ |
| +package linkstore |
| + |
| +import ( |
| + "testing" |
| + "time" |
| +) |
| + |
| +func TestFreshStartRejectsEarlierHomeAuthentication(t *testing.T) { |
| + s, _ := fixture(t) |
| + l := local(1) |
| + secret, err := s.StartFresh(ctx, l, "/", testNow) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if err = s.BindNonce(ctx, secret, l, nonce(1), testNow); err != nil { |
| + t.Fatal(err) |
| + } |
| + _, err = s.Complete(ctx, secret, l, Home{Issuer: issuer, Subject: "person", Nonce: nonce(1), AuthTime: testNow.Add(-time.Second)}, testNow) |
| + refused(t, err) |
| +} |
| +func TestCompleteOnRollbackRetainsInitiation(t *testing.T) { |
| + s, _ := fixture(t) |
| + l := local(1) |
| + secret := start(t, s, l, nonce(1)) |
| + tx, err := s.db.Begin() |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + _, err = s.CompleteOn(ctx, tx, secret, l, Home{Issuer: issuer, Subject: "person", Nonce: nonce(1), AuthTime: testNow}, testNow) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + tx.Rollback() |
| + if _, err = s.Complete(ctx, secret, l, Home{Issuer: issuer, Subject: "person", Nonce: nonce(1), AuthTime: testNow}, testNow); err != nil { |
| + t.Fatal("rollback consumed initiation", err) |
| + } |
| +} |
| + |
| +func TestStartFreshOnRollsBack(t *testing.T) { |
| + s, _ := fixture(t) |
| + tx, e := s.db.Begin() |
| + if e != nil { |
| + t.Fatal(e) |
| + } |
| + if _, e = s.StartFreshOn(ctx, tx, local(1), "/", testNow); e != nil { |
| + t.Fatal(e) |
| + } |
| + tx.Rollback() |
| + if flowCount(t, s) != 0 { |
| + t.Fatal("initiation escaped transaction") |
| + } |
| +} |
diff --git a/connect/linkstore/flows.go b/connect/linkstore/flows.go| index 567fa3c..7c29d8a 100644 |
| --- a/connect/linkstore/flows.go |
| +++ b/connect/linkstore/flows.go |
| @@ -14,6 +14,7 @@ import ( |
| ) |
| type flow struct { |
| + Started int64 `json:"started,omitempty"` |
| PersonBinding string `json:"person_binding"` |
| Version int `json:"v"` |
| PersonID int64 `json:"person"` |
| @@ -102,30 +103,57 @@ func (s *Store) currentBinding(ctx context.Context, tx *sql.Tx, id int64) (strin |
| // Start is called only by an explicit same-origin local-account link POST. |
| // The returned secret belongs in a host-only Secure/HttpOnly/Lax cookie. |
| func (s *Store) Start(ctx context.Context, local Local, returnPath string, now time.Time) (string, error) { |
| - tx, high, err := s.begin(ctx, now) |
| + return s.start(ctx, local, returnPath, now, false) |
| +} |
| + |
| +// StartFresh requires Home authentication at or after this initiation. |
| +func (s *Store) StartFresh(ctx context.Context, local Local, returnPath string, now time.Time) (string, error) { |
| + return s.start(ctx, local, returnPath, now, true) |
| +} |
| +func (s *Store) start(ctx context.Context, local Local, returnPath string, now time.Time, fresh bool) (string, error) { |
| + tx, _, err := s.begin(ctx, now) |
| if err != nil { |
| return "", err |
| } |
| defer tx.Rollback() |
| + result, err := s.startOn(ctx, tx, local, returnPath, now, fresh) |
| + if err != nil && !errors.Is(err, ErrRefused) { |
| + return "", err |
| + } |
| + if e := commit(tx); e != nil { |
| + return "", e |
| + } |
| + return result, err |
| +} |
| + |
| +// StartFreshOn creates fresh linking intent inside the caller's transaction. |
| +func (s *Store) StartFreshOn(ctx context.Context, tx *sql.Tx, local Local, returnPath string, now time.Time) (string, error) { |
| + return s.startOn(ctx, tx, local, returnPath, now, true) |
| +} |
| +func (s *Store) startOn(ctx context.Context, tx *sql.Tx, local Local, returnPath string, now time.Time, fresh bool) (string, error) { |
| + high, err := s.clockOn(ctx, tx, now) |
| + if err != nil { |
| + return "", err |
| + } |
| if err = sweep(ctx, tx, high); err != nil { |
| return "", err |
| } |
| if !validLocal(local, now.Unix(), high) { |
| - return "", refuse(tx) |
| + return "", ErrRefused |
| } |
| binding, err := s.currentBinding(ctx, tx, local.PersonID) |
| if err != nil { |
| return "", err |
| } |
| if binding == "" { |
| - return "", refuse(tx) |
| + return "", ErrRefused |
| } |
| var count int |
| if err := tx.QueryRowContext(ctx, "SELECT COUNT(*) FROM home_link_flows").Scan(&count); err != nil { |
| return "", ErrStorage |
| } |
| if count >= maxFlows { |
| - return "", refuse(tx) |
| + return "", ErrRefused |
| } |
| secret, err := newSecret() |
| if err != nil { |
| @@ -133,13 +161,13 @@ func (s *Store) Start(ctx context.Context, local Local, returnPath string, now t |
| } |
| expires := min(now.Unix()+maxAge, local.AuthTime.Unix()+maxAge) |
| if expires <= high { |
| - return "", refuse(tx) |
| + return "", ErrRefused |
| } |
| f := flow{PersonBinding: binding, Version: 1, PersonID: local.PersonID, SessionHash: hash(local.SessionToken), LocalAuth: local.AuthTime.Unix(), Issuer: s.issuer, ReturnPath: safePath(returnPath), Expires: expires} |
| - if err := s.put(ctx, tx, "init", hash(secret), f); err != nil { |
| - return "", err |
| + if fresh { |
| + f.Started = now.Unix() |
| } |
| - if err := commit(tx); err != nil { |
| + if err := s.put(ctx, tx, "init", hash(secret), f); err != nil { |
| return "", err |
| } |
| return secret, nil |
| @@ -184,31 +212,47 @@ func (s *Store) BindNonce(ctx context.Context, secret string, local Local, nonce |
| // Complete consumes the initiation after the shared consumer has consumed and |
| // verified the Home assertion. It keeps the local Docs session intact. |
| func (s *Store) Complete(ctx context.Context, secret string, local Local, home Home, now time.Time) (string, error) { |
| + tx, _, err := s.begin(ctx, now) |
| + if err != nil { |
| + return "", err |
| + } |
| + defer tx.Rollback() |
| + result, err := s.CompleteOn(ctx, tx, secret, local, home, now) |
| + if err != nil && !errors.Is(err, ErrRefused) { |
| + return "", err |
| + } |
| + if e := commit(tx); e != nil { |
| + return "", e |
| + } |
| + return result, err |
| +} |
| + |
| +// CompleteOn uses the caller-owned writer transaction; it never commits. |
| +func (s *Store) CompleteOn(ctx context.Context, tx *sql.Tx, secret string, local Local, home Home, now time.Time) (string, error) { |
| id, ok := secretHash(secret) |
| if !ok { |
| return "", ErrRefused |
| } |
| - tx, high, err := s.begin(ctx, now) |
| + high, err := s.clockOn(ctx, tx, now) |
| if err != nil { |
| return "", err |
| } |
| - defer tx.Rollback() |
| f, err := s.load(ctx, tx, "init", id, high, true) |
| if errors.Is(err, ErrRefused) { |
| - return "", refuse(tx) |
| + return "", ErrRefused |
| } |
| if err != nil { |
| return "", err |
| } |
| - if !s.matches(f, local, now.Unix(), high) || !handoff.ValidNonce(home.Nonce) || f.NonceHash != hash(home.Nonce) || home.Issuer != s.issuer || !validSubject(home.Subject) || !fresh(home.AuthTime.Unix(), now.Unix(), high) { |
| - return "", refuse(tx) |
| + if !s.matches(f, local, now.Unix(), high) || !handoff.ValidNonce(home.Nonce) || f.NonceHash != hash(home.Nonce) || home.Issuer != s.issuer || !validSubject(home.Subject) || !fresh(home.AuthTime.Unix(), now.Unix(), high) || home.AuthTime.Unix() < f.Started { |
| + return "", ErrRefused |
| } |
| binding, err := s.currentBinding(ctx, tx, local.PersonID) |
| if err != nil { |
| return "", err |
| } |
| if binding == "" || !hmac.Equal([]byte(binding), []byte(f.PersonBinding)) { |
| - return "", refuse(tx) |
| + return "", ErrRefused |
| } |
| pending, err := newSecret() |
| if err != nil { |
| @@ -217,14 +261,11 @@ func (s *Store) Complete(ctx context.Context, secret string, local Local, home H |
| f.Subject, f.HomeAuth = home.Subject, home.AuthTime.Unix() |
| f.Expires = min(f.Expires, f.HomeAuth+maxAge) |
| if f.Expires <= high { |
| - return "", refuse(tx) |
| + return "", ErrRefused |
| } |
| if err := s.put(ctx, tx, "pending", hash(pending), f); err != nil { |
| return "", err |
| } |
| - if err := commit(tx); err != nil { |
| - return "", err |
| - } |
| return pending, nil |
| } |
| @@ -277,31 +318,47 @@ func (s *Store) Pending(ctx context.Context, secret string, local Local, now tim |
| // mapping write commit together. A separate proof for the same mapping is |
| // idempotent; a reused cookie or conflicting mapping is consumed and refused. |
| func (s *Store) Confirm(ctx context.Context, secret string, local Local, now time.Time) (Pending, error) { |
| + tx, _, err := s.begin(ctx, now) |
| + if err != nil { |
| + return Pending{}, err |
| + } |
| + defer tx.Rollback() |
| + result, err := s.ConfirmOn(ctx, tx, secret, local, now) |
| + if err != nil && !errors.Is(err, ErrRefused) { |
| + return Pending{}, err |
| + } |
| + if e := commit(tx); e != nil { |
| + return Pending{}, e |
| + } |
| + return result, err |
| +} |
| + |
| +// ConfirmOn uses the caller-owned writer transaction; it never commits. |
| +func (s *Store) ConfirmOn(ctx context.Context, tx *sql.Tx, secret string, local Local, now time.Time) (Pending, error) { |
| id, ok := secretHash(secret) |
| if !ok { |
| return Pending{}, ErrRefused |
| } |
| - tx, high, err := s.begin(ctx, now) |
| + high, err := s.clockOn(ctx, tx, now) |
| if err != nil { |
| return Pending{}, err |
| } |
| - defer tx.Rollback() |
| f, err := s.load(ctx, tx, "pending", id, high, true) |
| if errors.Is(err, ErrRefused) { |
| - return Pending{}, refuse(tx) |
| + return Pending{}, ErrRefused |
| } |
| if err != nil { |
| return Pending{}, err |
| } |
| if !s.matches(f, local, now.Unix(), high) || !validPending(f, now.Unix(), high) { |
| - return Pending{}, refuse(tx) |
| + return Pending{}, ErrRefused |
| } |
| binding, err := s.currentBinding(ctx, tx, local.PersonID) |
| if err != nil { |
| return Pending{}, err |
| } |
| if binding == "" || !hmac.Equal([]byte(binding), []byte(f.PersonBinding)) { |
| - return Pending{}, refuse(tx) |
| + return Pending{}, ErrRefused |
| } |
| _, err = tx.ExecContext(ctx, "INSERT INTO home_identity_links (issuer, subject, person_id, person_binding) VALUES (?, ?, ?, ?) ON CONFLICT DO NOTHING", s.issuer, f.Subject, f.PersonID, f.PersonBinding) |
| if err != nil { |
| @@ -311,16 +368,27 @@ func (s *Store) Confirm(ctx context.Context, secret string, local Local, now tim |
| var storedBinding string |
| err = tx.QueryRowContext(ctx, "SELECT person_id, person_binding FROM home_identity_links WHERE issuer = ? AND subject = ?", s.issuer, f.Subject).Scan(&person, &storedBinding) |
| if errors.Is(err, sql.ErrNoRows) { |
| - return Pending{}, refuse(tx) |
| + return Pending{}, ErrRefused |
| } |
| if err != nil { |
| return Pending{}, ErrStorage |
| } |
| if person != f.PersonID || !hmac.Equal([]byte(storedBinding), []byte(f.PersonBinding)) { |
| - return Pending{}, refuse(tx) |
| - } |
| - if err := commit(tx); err != nil { |
| - return Pending{}, err |
| + return Pending{}, ErrRefused |
| } |
| return pendingView(f), nil |
| } |
| + |
| +func (s *Store) clockOn(ctx context.Context, tx *sql.Tx, now time.Time) (int64, error) { |
| + if _, err := tx.ExecContext(ctx, "UPDATE home_link_clock SET high_water=MAX(high_water,?) WHERE id=1", now.Unix()); err != nil { |
| + return 0, ErrStorage |
| + } |
| + var high int64 |
| + if err := tx.QueryRowContext(ctx, "SELECT high_water FROM home_link_clock WHERE id=1").Scan(&high); err != nil { |
| + return 0, ErrStorage |
| + } |
| + if now.Unix() < high-30 { |
| + return 0, ErrRefused |
| + } |
| + return high, nil |
| +} |
diff --git a/handoff/atomic_test.go b/handoff/atomic_test.go| new file mode 100644 |
| index 0000000..82b327b |
| --- /dev/null |
| +++ b/handoff/atomic_test.go |
| @@ -0,0 +1,42 @@ |
| +package handoff |
| + |
| +import ( |
| + "amadan.net/rastrillo/rastrillo/assertion" |
| + "context" |
| + "database/sql" |
| + "testing" |
| +) |
| + |
| +func TestReceivePendingRefusesUnknownNonce(t *testing.T) { |
| + f := fresh(t) |
| + _, nonce := f.pending(t) |
| + f.db.Exec("DELETE FROM oficina_handoff_pending") |
| + if _, err := f.s.ReceivePending(context.Background(), f.token(t, nonce), f.now); err != ErrRefused { |
| + t.Fatalf("unknown nonce: %v", err) |
| + } |
| + if count(t, f.db, "oficina_handoff_inbox") != 0 { |
| + t.Fatal("retained unsolicited receipt") |
| + } |
| +} |
| +func TestFinishAtomicRollsBackAppAndProof(t *testing.T) { |
| + f := fresh(t) |
| + secret, nonce := f.pending(t) |
| + handle, _ := f.received(t, nonce) |
| + f.db.Exec("CREATE TABLE minted (subject TEXT)") |
| + _, _, err := f.s.FinishAtomic(context.Background(), secret, handle, "", f.now, func(tx *sql.Tx, c assertion.Claims, _ string) error { |
| + if _, e := tx.Exec("INSERT INTO minted VALUES(?)", c.Subject); e != nil { |
| + t.Fatal(e) |
| + } |
| + return ErrRefused |
| + }) |
| + if err != ErrRefused || count(t, f.db, "minted") != 0 || count(t, f.db, "oficina_handoff_pending") != 1 { |
| + t.Fatal("partial commit", err) |
| + } |
| + _, _, err = f.s.FinishAtomic(context.Background(), secret, handle, "", f.now, func(tx *sql.Tx, c assertion.Claims, _ string) error { |
| + _, e := tx.Exec("INSERT INTO minted VALUES(?)", c.Subject) |
| + return e |
| + }) |
| + if err != nil || count(t, f.db, "minted") != 1 || count(t, f.db, "oficina_handoff_pending") != 0 { |
| + t.Fatal("atomic completion", err) |
| + } |
| +} |
diff --git a/handoff/store.go b/handoff/store.go| index 65c2281..30f76fd 100644 |
| --- a/handoff/store.go |
| +++ b/handoff/store.go |
| @@ -267,6 +267,15 @@ func (s *Store) cancel(ctx context.Context, secret string) error { |
| // Receive deliberately needs no cookie: a cross-site POST may carry none. A |
| // repeated assertion gets no new inbox row or cookie, even before Finish runs. |
| func (s *Store) Receive(ctx context.Context, token string, now time.Time) (string, error) { |
| + return s.receive(ctx, token, now, false) |
| +} |
| + |
| +// ReceivePending refuses receipts without a live browser transaction. |
| +func (s *Store) ReceivePending(ctx context.Context, token string, now time.Time) (string, error) { |
| + return s.receive(ctx, token, now, true) |
| +} |
| + |
| +func (s *Store) receive(ctx context.Context, token string, now time.Time, requirePending bool) (string, error) { |
| claims, e := s.verifier.Verify(token, now) |
| if e != nil { |
| return "", ErrRefused |
| @@ -287,6 +296,14 @@ func (s *Store) Receive(ctx context.Context, token string, now time.Time) (strin |
| } |
| defer tx.Rollback() |
| var count int |
| + if requirePending { |
| + if e = tx.QueryRowContext(ctx, `SELECT COUNT(*) FROM oficina_handoff_pending WHERE nonce_hash=? AND expires_at>?`, digest(claims.Nonce), n).Scan(&count); e != nil { |
| + return "", ErrStorage |
| + } |
| + if count != 1 { |
| + return "", ErrRefused |
| + } |
| + } |
| if e = tx.QueryRowContext(ctx, `SELECT COUNT(*) FROM oficina_handoff_replay WHERE jti_hash=?`, jti).Scan(&count); e != nil { |
| return "", ErrStorage |
| } |
| @@ -322,6 +339,12 @@ func (s *Store) Receive(ctx context.Context, token string, now time.Time) (strin |
| // existingSubject is resolved before calling: reading a session from inside |
| // this transaction could deadlock an app's single-connection writer. |
| func (s *Store) Finish(ctx context.Context, secret, handle, existingSubject string, now time.Time) (assertion.Claims, string, error) { |
| + return s.FinishAtomic(ctx, secret, handle, existingSubject, now, nil) |
| +} |
| + |
| +// FinishAtomic consumes the exchange and applies the consumer mutation in one writer transaction. |
| +// The hook must use tx for every lookup and write, and must not publish a cookie before commit. |
| +func (s *Store) FinishAtomic(ctx context.Context, secret, handle, existingSubject string, now time.Time, complete func(*sql.Tx, assertion.Claims, string) error) (assertion.Claims, string, error) { |
| zero := assertion.Claims{} |
| if !validHandle(secret) || !validHandle(handle) { |
| return zero, "", ErrRefused |
| @@ -383,6 +406,17 @@ func (s *Store) Finish(ctx context.Context, secret, handle, existingSubject stri |
| return zero, "", ErrStorage |
| } |
| } |
| + if fresh && (claims.AuthTime > n || fence-claims.AuthTime > freshAuthLifetime) { |
| + if tx.Commit() != nil { |
| + return zero, "", ErrStorage |
| + } |
| + return zero, "", ErrRefused |
| + } |
| + if complete != nil { |
| + if e = complete(tx, claims, string(path)); e != nil { |
| + return zero, "", e |
| + } |
| + } |
| if tx.Commit() != nil { |
| return zero, "", ErrStorage |
| } |
diff --git a/internal/home/id_direct.go b/internal/home/id_direct.go| index 7fc7be5..cebd1c0 100644 |
| --- a/internal/home/id_direct.go |
| +++ b/internal/home/id_direct.go |
| @@ -57,10 +57,6 @@ func consumeDirect(tx *sql.Tx, challenge []byte, expires, now int64) error { |
| if _, err := tx.Exec("DELETE FROM home_id_direct_used WHERE expires_at<=?", now); err != nil { |
| return errIDProof |
| } |
| - var n int |
| - if tx.QueryRow("SELECT count(*) FROM home_id_direct_used").Scan(&n) != nil || n >= 10000 { |
| - return errIDProof |
| - } |
| if _, err := tx.Exec("INSERT INTO home_id_direct_used VALUES(?,?)", hex.EncodeToString(challenge), expires); err != nil { |
| return errIDProof |
| } |
diff --git a/internal/home/id_followups_test.go b/internal/home/id_followups_test.go| new file mode 100644 |
| index 0000000..98a122a |
| --- /dev/null |
| +++ b/internal/home/id_followups_test.go |
| @@ -0,0 +1,49 @@ |
| +package home |
| + |
| +import ( |
| + "amadan.net/oficina/home/internal/home/sealtest" |
| + "amadan.net/rastrillo/rastrillo/webauthn/authtest" |
| + "net/http/httptest" |
| + "net/url" |
| + "strings" |
| + "testing" |
| +) |
| + |
| +func TestIDZeroCodesPreservesReturn(t *testing.T) { |
| + a := newTestApp(t) |
| + s := signInFully(t, a, sealtest.CanaryAddress) |
| + k := enrol(t, a, s) |
| + target := "/authorize/resume" |
| + w := httptest.NewRecorder() |
| + writeReturn(w, target) |
| + b := idJSON(t, a, "/passkey/direct/begin", nil) |
| + zero := uint32(0) |
| + done := idJSON(t, a, "/passkey/direct/finish", assertionBody(k, challengeFrom(t, b), authtest.Options{RPID: credentialHost, Origin: Origin, Count: &zero}), namedCookie(t, b, ceremonyCookie), w.Result().Cookies()[0]) |
| + if !strings.Contains(done.Body.String(), "return_to=") { |
| + t.Fatal("lost original target", done.Body.String()) |
| + } |
| + path := "/passkey/codes?return_to=" + url.QueryEscape(target) |
| + page := exchangeRequest(a.App, "GET", Origin+path, "", nil, sessionCookie(done)) |
| + if !strings.Contains(page.Body.String(), `name="return_to" value="/authorize/resume"`) { |
| + t.Fatal("codes form lost return target") |
| + } |
| + codes := exchangeRequest(a.App, "POST", Origin+"/passkey/codes", Origin, url.Values{"return_to": {target}}, sessionCookie(done)) |
| + if !strings.Contains(codes.Body.String(), `href="/authorize/resume"`) { |
| + t.Fatal("no continuation after codes") |
| + } |
| +} |
| + |
| +func TestIDCredentialReturnLocalOnly(t *testing.T) { |
| + for _, value := range []string{"/passkey/enrol", "/passkey/codes", "/authorize/resume", "/dashboard/resume", operatorConfirm, resolvePath} { |
| + if got := credentialReturn(value); got != value { |
| + t.Fatalf("allowed return %q became %q", value, got) |
| + } |
| + } |
| + for _, value := range []string{"https://evil.example/authorize/resume", "http:/authorize/resume", "javascript:alert(1)", "//evil.example/authorize/resume", "///evil.example", `\\evil.example`, `/\evil.example`, `/authorize\resume`, "%2f%2fevil.example", "/%2f%2fevil.example", "/%5cevil.example", "/authorize/resume?return_to=//evil.example", "/authorize/resume#//evil.example", "\n//evil.example", "/authorize/resume\r\nLocation: https://evil.example", "authorize/resume", ""} { |
| + t.Run(value, func(t *testing.T) { |
| + if got := credentialReturn(value); got != "/" { |
| + t.Fatalf("unsafe return %q accepted as %q", value, got) |
| + } |
| + }) |
| + } |
| +} |
diff --git a/internal/home/id_passkey.go b/internal/home/id_passkey.go| index 634d06f..9c3c9f3 100644 |
| --- a/internal/home/id_passkey.go |
| +++ b/internal/home/id_passkey.go |
| @@ -8,6 +8,7 @@ import ( |
| "encoding/json" |
| "errors" |
| "net/http" |
| + "net/url" |
| "strings" |
| "time" |
| @@ -396,7 +397,11 @@ func (a *App) idFinish(purpose string) http.HandlerFunc { |
| return |
| } |
| if codes == 0 { |
| - to = "/passkey/codes" |
| + if to != "/" && to != "/passkey/codes" { |
| + to = "/passkey/codes?return_to=" + url.QueryEscape(credentialReturn(to)) |
| + } else { |
| + to = "/passkey/codes" |
| + } |
| } |
| token, e := a.idMint(tx, r, sessions.Session{Subject: owner, Method: method, AuthTime: time.Unix(now, 0)}, now) |
| if e != nil { |
diff --git a/internal/home/id_review_test.go b/internal/home/id_review_test.go| index 47170ed..c3646d9 100644 |
| --- a/internal/home/id_review_test.go |
| +++ b/internal/home/id_review_test.go |
| @@ -303,8 +303,8 @@ func TestIDDirectReceiptsBounded(t *testing.T) { |
| r := idJSON(t, a, "/passkey/direct/finish", body, c) |
| switch kind { |
| case "capacity": |
| - if r.Code == 200 { |
| - t.Fatal("receipt cap bypassed") |
| + if r.Code != 200 { |
| + t.Fatal("another credential can exhaust direct sign-in") |
| } |
| case "expiry": |
| if r.Code != 200 { |
diff --git a/internal/home/passkey.go b/internal/home/passkey.go| index 7bb04c7..1dcce38 100644 |
| --- a/internal/home/passkey.go |
| +++ b/internal/home/passkey.go |
| @@ -131,7 +131,7 @@ func (a *App) handleRecoveryCodesPage(w http.ResponseWriter, r *http.Request) { |
| a.serverError(w, r) |
| return |
| } |
| - a.render(w, r, http.StatusOK, "recovery_codes.html", map[string]any{"Remaining": remaining}) |
| + a.render(w, r, http.StatusOK, "recovery_codes.html", map[string]any{"Remaining": remaining, "ReturnTo": credentialReturn(r.URL.Query().Get("return_to"))}) |
| } |
| // handleRegenerateRecoveryCodes mints a fresh set and shows it once. |
| @@ -170,7 +170,7 @@ func (a *App) handleRegenerateRecoveryCodes(w http.ResponseWriter, r *http.Reque |
| a.serverError(w, r) |
| return |
| } |
| - a.render(w, r, http.StatusOK, "recovery_codes.html", map[string]any{"Codes": codes}) |
| + a.render(w, r, http.StatusOK, "recovery_codes.html", map[string]any{"Codes": codes, "ReturnTo": credentialReturn(r.FormValue("return_to"))}) |
| } |
| // serveAsset serves one of the two script files. |
diff --git a/internal/home/templates/recovery_codes.html b/internal/home/templates/recovery_codes.html| index 36c0bc0..e4a801f 100644 |
| --- a/internal/home/templates/recovery_codes.html |
| +++ b/internal/home/templates/recovery_codes.html |
| @@ -11,7 +11,9 @@ There is no operator who can undo that, by design.</p> |
| <p>You have {{.Data.Remaining}} unused recovery codes.</p> |
| <p>Generating a new set <strong>invalidates every code you have now</strong>.</p> |
| <form method="post" action="/passkey/codes"> |
| + <input type="hidden" name="return_to" value="{{.Data.ReturnTo}}"> |
| <button type="submit" rst-btn="danger">Generate a new set</button> |
| </form> |
| {{end}} |
| +{{if .Data.Codes}}<a rst-btn href="{{.Data.ReturnTo}}">Continue</a>{{end}} |
| {{end}} |