oficina / home Public

connect: Fable's review fixes — the writer-held gate fails fast; sign-out drops the choice row

Human

Prompt

Fable reviewed: APPROVE AFTER FIXES — fix the writer-held gate hang, cover a known person's web finish, nits, and the native-nonce comment.

From this commit's own message. The prompt ledger has no entries for it — which is what a squashed, rebased or amended commit looks like, and what every commit looks like in a repo without a ledger.

Summary

TestNoHookRunsWithTheWriterHeld now fails at the hook that finds the writer held ('called with the writer held: [Unlinked]', ~2s; proved by mutating allocate to hold a transaction across Unlinked, which hung >3 min before) and also covers a known person's browser finish (HomeOnly + MintHomeSession in complete). Sign-out deletes the pending choice-proof row (linkstore DropChoice), not just its cookie. CurrentSubject ignores an Expired Home-derived session. MintNativeSession's contract states the store lifetime must be at least NativeLifetime. native.go notes the accepted /authorize caller-chosen-nonce residual.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev c70205a5e1a27fb8da97ca262579f2e2e430dbcd parent a4da657
7 files changed, +68 −24
  • connect/api.go +3 −1
  • connect/bridge.go +1 −1
  • connect/linkstore/choice.go +12 −0
  • connect/native.go +5 −0
  • connect/native_test.go +25 −22
  • connect/routes.go +5 −0
  • connect/unlinked_test.go +17 −0

CI passed — run details

diff --git a/connect/api.go b/connect/api.go
index 3a40903..8dbd217 100644
--- a/connect/api.go
+++ b/connect/api.go
@@ -130,7 +130,9 @@ type Config struct {
// returns its cookie value, which the app's native client then sends
// as SessionCookie. It must set no cookie, and it is called with no
// transaction open. connect refuses the session NativeLifetime after
- // its At (Expired), so the store must record At at creation.
+ // its At (Expired), so the store must record At at creation, and its
+ // own lifetime must be at least NativeLifetime: the answer promises the
+ // app expires_at = now + NativeLifetime.
MintNativeSession func(ctx context.Context, s Session) (string, error)
}
diff --git a/connect/bridge.go b/connect/bridge.go
index 19f815e..c0f5a2b 100644
--- a/connect/bridge.go
+++ b/connect/bridge.go
@@ -77,7 +77,7 @@ func New(c Config) (*Bridge, error) {
b := &Bridge{namespace: c.Namespace, keyHash: sha256.Sum256(c.DEK), origin: c.Origin, issuer: c.Issuer, sessionCookie: c.SessionCookie, links: linker, now: now, returnPath: c.ReturnPath, readSession: c.ReadSession, mintSession: c.MintHomeSession, localPerson: c.LookupLocalSession, render: c.Render, unlinked: c.Unlinked, homeOnly: c.HomeOnly, admit: c.Admit, formKey: formKey(c.DEK, c.Origin), exchange: exchange, mintNative: c.MintNativeSession}
cfg := handoff.ConsumerConfig{Store: exchange, ConsumerID: c.ConsumerID, Complete: b.complete, Fail: b.fail, Now: func() time.Time { return b.now() }, CurrentSubject: func(r *http.Request) string {
result, _ := r.Context().Value(homeFinishKey{}).(*homeFinishResult)
- if result != nil && result.session != nil && IsHomeDerived(result.session.Method) {
+ if result != nil && result.session != nil && IsHomeDerived(result.session.Method) && !Expired(*result.session, b.now()) {
return result.session.Subject
}
return ""
diff --git a/connect/linkstore/choice.go b/connect/linkstore/choice.go
index d7dc606..8e07a4f 100644
--- a/connect/linkstore/choice.go
+++ b/connect/linkstore/choice.go
@@ -136,6 +136,18 @@ func (s *Store) TakeChoice(ctx context.Context, secret string, now time.Time) (C
return c, nil
}
+// DropChoice deletes a proof by its secret, consuming it unused: sign-out.
+func (s *Store) DropChoice(ctx context.Context, secret string) error {
+ id, ok := secretHash(secret)
+ if !ok {
+ return ErrRefused
+ }
+ if _, err := s.db.ExecContext(ctx, "DELETE FROM home_choice_proofs WHERE id_hash = ?", id); err != nil {
+ return ErrStorage
+ }
+ return nil
+}
+
func (s *Store) openChoice(id string, expires int64, raw []byte, now int64) (Choice, error) {
if len(raw) > 4096 || expires <= now {
return Choice{}, ErrRefused
diff --git a/connect/native.go b/connect/native.go
index b097e3d..bb0fe2d 100644
--- a/connect/native.go
+++ b/connect/native.go
@@ -138,6 +138,11 @@ func (b *Bridge) NativeExchange(w http.ResponseWriter, r *http.Request) {
nativeAnswer(w, nativeFailed)
return
}
+ // Known and accepted (Fable, 2026-11-14 review; recorded in the spec):
+ // an instance cannot tell this assertion from a browser one that
+ // /authorize minted with a caller-chosen nonce equal to a native nonce.
+ // Only the subject's own browser can do that, for itself, so it grants
+ // nothing the person does not already have.
nonce, _ := handoff.NativeNonce(challenge)
if subtle.ConstantTimeCompare([]byte(nonce), []byte(claims.Nonce)) != 1 {
nativeAnswer(w, nativeFailed)
diff --git a/connect/native_test.go b/connect/native_test.go
index cc0a2aa..a6bd4a6 100644
--- a/connect/native_test.go
+++ b/connect/native_test.go
@@ -410,35 +410,38 @@ func TestNativeConcurrentChoicesMakeOnePerson(t *testing.T) {
// No hook and no mint is ever called with connect holding the writer. On a
// single-connection pool (Docs' writer), each hook needs the connection; a
-// transaction held across it would make the hook wait, and it fails the
-// test after a second instead of wedging the pool.
+// transaction held across it would make the hook wait forever. The probe
+// waits a second instead, and a hook that finds the writer held fails the
+// test there and then, before it or anything after it touches the pool.
+// Every hook runs on the test goroutine (the handlers are called directly),
+// so Fatalf is safe here.
func TestNoHookRunsWithTheWriterHeld(t *testing.T) {
- var mu sync.Mutex
- var held []string
- var probe func(string)
+ var probe func(string) bool
h := &homeOnlyHooks{}
f := newBridgeFixtureWith(t, func(f *bridgeFixture, c *Config) {
h.install(f, c)
f.db.SetMaxOpenConns(1)
- probe = func(name string) {
+ probe = func(string) bool {
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
- if _, err := f.db.ExecContext(ctx, "UPDATE home_link_clock SET high_water = high_water WHERE id = 1"); err != nil {
- mu.Lock()
- held = append(held, name)
- mu.Unlock()
+ _, err := f.db.ExecContext(ctx, "UPDATE home_link_clock SET high_water = high_water WHERE id = 1")
+ return err != nil
+ }
+ free := func(name string) {
+ if probe(name) {
+ t.Fatalf("called with the writer held: [%s]", name)
}
}
admit, unlinked, homeOnly, mint := c.Admit, c.Unlinked, c.HomeOnly, c.MintHomeSession
- c.Admit = func(ctx context.Context, i, s string) error { probe("Admit"); return admit(ctx, i, s) }
- c.Unlinked = func(ctx context.Context, i, s string) (Person, error) { probe("Unlinked"); return unlinked(ctx, i, s) }
- c.HomeOnly = func(ctx context.Context, i, s string) (Person, error) { probe("HomeOnly"); return homeOnly(ctx, i, s) }
+ c.Admit = func(ctx context.Context, i, s string) error { free("Admit"); return admit(ctx, i, s) }
+ c.Unlinked = func(ctx context.Context, i, s string) (Person, error) { free("Unlinked"); return unlinked(ctx, i, s) }
+ c.HomeOnly = func(ctx context.Context, i, s string) (Person, error) { free("HomeOnly"); return homeOnly(ctx, i, s) }
c.MintHomeSession = func(w http.ResponseWriter, r *http.Request, s Session) error {
- probe("MintHomeSession")
+ free("MintHomeSession")
return mint(w, r, s)
}
c.MintNativeSession = func(_ context.Context, s Session) (string, error) {
- probe("MintNativeSession")
+ free("MintNativeSession")
return f.sessions.Mint(s)
}
})
@@ -447,14 +450,17 @@ func TestNoHookRunsWithTheWriterHeld(t *testing.T) {
if err != nil {
t.Fatal(err)
}
- probe("self-check")
+ seen := probe("self-check")
tx.Rollback()
- if len(held) != 1 {
+ if !seen {
t.Fatal("the probe cannot see a held writer")
}
- held = nil
- // The browser path: finish, the choose page, "I'm new here".
+ // The browser path: finish, the choose page, "I'm new here"; then a
+ // known person's finish (HomeOnly and MintHomeSession in complete).
f.signInNew(t, "pr_browser")
+ if w := f.finishAs(t, "pr_browser", nil); w.Code != 303 || w.Header().Get("Location") != "/next" {
+ t.Fatalf("known person's finish=%d %q", w.Code, w.Header().Get("Location"))
+ }
// The native path: 409, then choice "new", then a known person.
wantState(t, f.post(t, "pr_native", nil), 409, "choose")
f.signedSession(t, f.post(t, "pr_native", map[string]string{"choice": "new"}))
@@ -462,7 +468,4 @@ func TestNoHookRunsWithTheWriterHeld(t *testing.T) {
if h.admitted == 0 || h.unlinked != 2 || h.homeOnly == 0 {
t.Fatalf("hooks not exercised: admit=%d unlinked=%d homeOnly=%d", h.admitted, h.unlinked, h.homeOnly)
}
- if len(held) != 0 {
- t.Fatalf("called with the writer held: %v", held)
- }
}
diff --git a/connect/routes.go b/connect/routes.go
index 14060e6..42eb5b1 100644
--- a/connect/routes.go
+++ b/connect/routes.go
@@ -211,6 +211,11 @@ func (h *Routes) ConfirmPost(w http.ResponseWriter, r *http.Request) {
// here, as before.
func (h *Routes) Signout(w http.ResponseWriter, r *http.Request) {
h.cfg.SignOut(w, r)
+ // A pending member choice ends with the browser's sign-out: its row,
+ // not only its cookie. Best effort; the proof expires in ten minutes.
+ if secret, present, ok := homeCookie(r, homeChoiceCookie); present && ok && h.bridge.links != nil {
+ _ = h.bridge.links.DropChoice(r.Context(), secret)
+ }
for _, name := range []string{homeInitCookie, homeProofCookie, homeChoiceCookie, localLinkNavigationCookie, homeReturnCookie, "__Host-oficina-assertion-pending", "__Host-oficina-assertion-inbox"} {
localNavigationCookie(w, name, "", -1)
}
diff --git a/connect/unlinked_test.go b/connect/unlinked_test.go
index 6e13403..df10bda 100644
--- a/connect/unlinked_test.go
+++ b/connect/unlinked_test.go
@@ -563,3 +563,20 @@ func TestTeamHooksKeepConnectsCookieChecks(t *testing.T) {
t.Fatal("a malformed cookie reached a team hook")
}
}
+
+// Signing out ends a pending choice: the proof row goes, not just the cookie.
+func TestSignoutDropsAPendingChoice(t *testing.T) {
+ f, h := newHomeOnlyFixture(t)
+ routes := f.routes(t)
+ proof := bridgeCookie(t, f.finishAs(t, "pr_member", nil), homeChoiceCookie)
+ r := httptest.NewRequest(http.MethodPost, bridgeOrigin+"/signout", nil)
+ r.AddCookie(proof)
+ routes.Signout(httptest.NewRecorder(), r)
+ // The browser kept a copy of the cookie: it chooses nothing.
+ if w := f.choosePost(t, "new", f.b.choiceToken(proof.Value), []*http.Cookie{proof}); w.Code != 403 {
+ t.Fatalf("choice after sign-out=%d", w.Code)
+ }
+ if h.unlinked != 0 || h.count(t) != 0 {
+ t.Fatal("a signed-out choice allocated")
+ }
+}