Skip to content

fix(server): confirm a refresh token's grant by its key - #878

Merged
osanderson merged 1 commit into
mainfrom
fix/grant-registry-keyed-confirm
Nov 18, 2026
Merged

osanderson merged 1 commit into
mainfrom
fix/grant-registry-keyed-confirm

Conversation

@osanderson

Copy link
Copy Markdown
Collaborator

Problem

With Dependencies.GrantRegistry set, every refresh token issuance runs confirmGrantRecorded after storing the token. It listed all of the end user's grant entries to check that its own was still there.

  • An entry is added each time the user completes an authorization that issues a refresh token, and stays until that token expires or is revoked. FAPI forbids refresh-token rotation, so refreshing doesn't add entries, but completing authorizations does.
  • So the cost of each issuance grew with the user's live grants, and the total grew quadratically for an account that keeps authorizing.
  • sqlstore fetched and unsealed every row. memstore scanned every subject's entries.

A per-subject cap would still need that listing, and would refuse the user's new grant once it was reached. So this asks for the one entry instead.

Change

  • storage.GrantListing gains Key. With it set, a store may return only the entry with that key. A store that ignores it and lists the subject's entries as before is still correct, only slower. This isn't breaking for existing implementations.
  • confirmGrantRecorded sets Key and still searches whatever comes back.
  • memstore honours it with a map lookup.
  • TestGrantRegistryContract gains ListByKey. The keyed entry must be listed while it's the subject's and unexpired, and never for another subject.

sqlstore will honour Key with a primary-key read in a follow-up once this is released, since sqlstore builds against the released fapigo. Until then it lists as before, which is still correct.

Tests

  • TestRefreshTokenIssuanceConfirmsItsOwnEntry checks that issuance asks for its own entry by key, against a store that honours Key and one that ignores it.
  • TestGrantRegistryListsByKeyAlone checks memstore returns only the keyed entry.
  • Both fail when their part of the change is removed.

🤖 Generated with Claude Code

@codecov

codecov Bot commented Nov 18, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Each refresh token issued with a GrantRegistry set listed all of its
end user's grant entries to confirm its own was still recorded, so the
cost of issuance grew with the user's grants. In sqlstore that meant
fetching and unsealing every row. memstore scanned every subject's
entries.

storage.GrantListing gains Key. With it set, a store may return only
that entry, which the server now asks for. A store that ignores Key and
lists the subject's entries as before is still correct, only slower.
memstore honours it with one map lookup. The registry contract checks
the entry is listed by key and never another subject's.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@osanderson
osanderson force-pushed the fix/grant-registry-keyed-confirm branch from 4c5a129 to 4194907 Compare November 18, 2026 17:34
@sonarqubecloud

Copy link
Copy Markdown

@osanderson
osanderson merged commit 7610be9 into main Nov 18, 2026
33 checks passed
@osanderson
osanderson deleted the fix/grant-registry-keyed-confirm branch November 18, 2026 23:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant