From 570c54fea6db6c9df0dc6dd8bd6e238b1885a26f Mon Sep 17 00:00:00 2001 From: Oscar Sanderson Date: Thu, 26 Nov 2026 02:18:10 +0800 Subject: [PATCH 1/3] feat(sqlstore): report an unknown CIBA handle as not found to the server The backchannel store's lookup and decision for a handle it holds no request under wrapped only sqlstore.ErrNotFound, which the server doesn't recognise. Its inbox listing therefore reports an entry whose request is gone (expired and purged, say) as one it couldn't read. Both now also wrap storage.ErrBackchannelAuthenticationNotFound, so the listing leaves such an entry out and DenyBackchannelInteractions clears it. ErrNotFound is still wrapped, and the contract's optional subtests for the sentinel now run against both dialects. The sentinel first ships in fapigo v0.86.0, which sqlstore now requires. Co-Authored-By: Claude Opus 5.5 --- sqlstore/backchannel.go | 12 ++++++++++-- sqlstore/backchannel_test.go | 12 ++++++++---- sqlstore/go.mod | 2 +- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/sqlstore/backchannel.go b/sqlstore/backchannel.go index 06ea8d32..069b37ce 100644 --- a/sqlstore/backchannel.go +++ b/sqlstore/backchannel.go @@ -131,7 +131,7 @@ func (s *BackchannelAuthenticationStore) LookupBackchannelAuthentication(ctx con handleHash[:]).Scan(&key, &clientID, &stored, &bound.deliveryMode, &bound.pollInterval, &bound.expires) switch { case errors.Is(err, sql.ErrNoRows): - return storage.LookedUpBackchannelAuthentication{}, fmt.Errorf("sqlstore: look up backchannel authentication: %w", notFound("handle")) + return storage.LookedUpBackchannelAuthentication{}, unknownBackchannelHandle("look up backchannel authentication") case err != nil: return storage.LookedUpBackchannelAuthentication{}, unavailable("look up backchannel authentication", err) } @@ -194,6 +194,14 @@ func (s *BackchannelAuthenticationStore) DecideBackchannelAuthentication(ctx con return out, nil } +// unknownBackchannelHandle is op's error for a handle the store holds no +// request under: ErrNotFound, also wrapping +// storage.ErrBackchannelAuthenticationNotFound so the server can tell a +// request that is gone from any other refusal. +func unknownBackchannelHandle(op string) error { + return fmt.Errorf("sqlstore: %s: %w (%w)", op, notFound("handle"), storage.ErrBackchannelAuthenticationNotFound) +} + // whyUndecided is DecideBackchannelAuthentication's error for a handle // its UPDATE didn't decide: unknown, or already decided. func (s *BackchannelAuthenticationStore) whyUndecided(ctx context.Context, handleHash [32]byte) error { @@ -202,7 +210,7 @@ func (s *BackchannelAuthenticationStore) whyUndecided(ctx context.Context, handl return unavailable("decide backchannel authentication", err) } if n == 0 { - return fmt.Errorf("sqlstore: decide backchannel authentication: %w", notFound("handle")) + return unknownBackchannelHandle("decide backchannel authentication") } return errBackchannelDecided } diff --git a/sqlstore/backchannel_test.go b/sqlstore/backchannel_test.go index 5dc59799..e7ccf8e2 100644 --- a/sqlstore/backchannel_test.go +++ b/sqlstore/backchannel_test.go @@ -75,7 +75,8 @@ func TestBackchannelPollInterval(t *testing.T) { }) } -// A decision for an unknown handle is ErrNotFound; for a decided one, +// A decision for an unknown handle is ErrNotFound, and +// storage.ErrBackchannelAuthenticationNotFound; for a decided one, // storage.ErrBackchannelAuthenticationAlreadyDecided. Lookup keeps answering after the decision, and an approval // polled once is spent even after the request expires. func TestBackchannelDecisionsAndExpiry(t *testing.T) { @@ -84,13 +85,16 @@ func TestBackchannelDecisionsAndExpiry(t *testing.T) { b := freshDB(t, dialect).Backchannel() r := cibaRequest("r", "poll") must(t, b.CreateBackchannelAuthentication(ctx, r)) - if _, err := b.DecideBackchannelAuthentication(ctx, storage.DecideBackchannelAuthentication{HandleHash: sha256.Sum256([]byte("unknown")), Status: storage.BackchannelAuthenticationDenied}); !errors.Is(err, sqlstore.ErrNotFound) { - t.Fatalf("DecideBackchannelAuthentication(unknown) = %v, want ErrNotFound", err) + if _, err := b.DecideBackchannelAuthentication(ctx, storage.DecideBackchannelAuthentication{HandleHash: sha256.Sum256([]byte("unknown")), Status: storage.BackchannelAuthenticationDenied}); !errors.Is(err, sqlstore.ErrNotFound) || !errors.Is(err, storage.ErrBackchannelAuthenticationNotFound) { + t.Fatalf("DecideBackchannelAuthentication(unknown) = %v, want ErrNotFound and ErrBackchannelAuthenticationNotFound", err) + } + if _, err := b.LookupBackchannelAuthentication(ctx, sha256.Sum256([]byte("unknown"))); !errors.Is(err, sqlstore.ErrNotFound) || !errors.Is(err, storage.ErrBackchannelAuthenticationNotFound) { + t.Fatalf("LookupBackchannelAuthentication(unknown) = %v, want ErrNotFound and ErrBackchannelAuthenticationNotFound", err) } approve := storage.DecideBackchannelAuthentication{HandleHash: r.HandleHash, Status: storage.BackchannelAuthenticationApproved, Grant: secretGrant} _, err := b.DecideBackchannelAuthentication(ctx, approve) must(t, err) - if _, err := b.DecideBackchannelAuthentication(ctx, approve); !errors.Is(err, storage.ErrBackchannelAuthenticationAlreadyDecided) || errors.Is(err, sqlstore.ErrNotFound) || errors.Is(err, storage.ErrStoreUnavailable) { + if _, err := b.DecideBackchannelAuthentication(ctx, approve); !errors.Is(err, storage.ErrBackchannelAuthenticationAlreadyDecided) || errors.Is(err, sqlstore.ErrNotFound) || errors.Is(err, storage.ErrBackchannelAuthenticationNotFound) || errors.Is(err, storage.ErrStoreUnavailable) { t.Fatalf("second DecideBackchannelAuthentication = %v, want ErrBackchannelAuthenticationAlreadyDecided, not ErrNotFound", err) } if got, err := b.LookupBackchannelAuthentication(ctx, r.HandleHash); err != nil || got.ClientID != "c" || string(got.Request) != string(secretGrant) { diff --git a/sqlstore/go.mod b/sqlstore/go.mod index e41fecea..2bf0d8ee 100644 --- a/sqlstore/go.mod +++ b/sqlstore/go.mod @@ -3,7 +3,7 @@ module github.com/idfoundry/fapigo/sqlstore go 1.26.11 require ( - github.com/idfoundry/fapigo v0.84.0 + github.com/idfoundry/fapigo v0.86.0 github.com/jackc/pgx/v5 v5.13.0 modernc.org/sqlite v1.62.0 ) From 46b4f5565c9b65f4c0d6e5e7072101841c71b4b0 Mon Sep 17 00:00:00 2001 From: Oscar Sanderson Date: Thu, 26 Nov 2026 11:52:09 +0800 Subject: [PATCH 2/3] chore(examples): require fapigo v0.86.0 in linked-accounts The example uses sqlstore, which now requires fapigo v0.86.0, so its own requirement has to be at least that for its go.mod to be tidy. Co-Authored-By: Claude Opus 5.5 --- examples/linked-accounts/go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/linked-accounts/go.mod b/examples/linked-accounts/go.mod index eedcaceb..ce3b62ee 100644 --- a/examples/linked-accounts/go.mod +++ b/examples/linked-accounts/go.mod @@ -3,7 +3,7 @@ module github.com/idfoundry/fapigo/examples/linked-accounts go 1.26.11 require ( - github.com/idfoundry/fapigo v0.84.0 + github.com/idfoundry/fapigo v0.86.0 github.com/idfoundry/fapigo/examples/internal/demokit v0.0.0-00010101000000-000000000000 github.com/idfoundry/fapigo/sqlstore v0.0.0-00010101000000-000000000000 modernc.org/sqlite v1.62.0 From 802a465ccb0a9483d86b58524a57585fdfee3288 Mon Sep 17 00:00:00 2001 From: Oscar Sanderson Date: Thu, 26 Nov 2026 11:52:10 +0800 Subject: [PATCH 3/3] test: add a mutant for sqlstore's not-found CIBA handle Co-Authored-By: Claude Opus 5.5 --- .github/mutation/mutants.json | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/.github/mutation/mutants.json b/.github/mutation/mutants.json index 3018dc37..80bbefdb 100644 --- a/.github/mutation/mutants.json +++ b/.github/mutation/mutants.json @@ -5802,5 +5802,17 @@ ], "run": "^TestLocalIssuerKeysBoundIssuer$", "why": "LocalIssuerKeys reports its own issuer as its binding" + }, + { + "id": "sqlstore-ciba-unknown-handle-wraps-notfound", + "file": "sqlstore/backchannel.go", + "old": "return fmt.Errorf(\"sqlstore: %s: %w (%w)\", op, notFound(\"handle\"), storage.ErrBackchannelAuthenticationNotFound)", + "new": "return fmt.Errorf(\"sqlstore: %s: %w (%v)\", op, notFound(\"handle\"), storage.ErrBackchannelAuthenticationNotFound)", + "module": "sqlstore", + "packages": [ + "." + ], + "run": "^TestBackchannelDecisionsAndExpiry$", + "why": "sqlstore wraps ErrBackchannelAuthenticationNotFound for an unknown CIBA handle" } ]