Skip to content

fix(server)!: bind stored digests to the issuer, and namespace access-token revocation keys - #967

Merged
osanderson merged 7 commits into
mainfrom
fix/issuer-separated-keys
Nov 25, 2026
Merged

osanderson merged 7 commits into
mainfrom
fix/issuer-separated-keys

Conversation

@osanderson

@osanderson osanderson commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

Breaking. This makes two decided changes to stored keys, from the audit's defence-in-depth list (G.3; coverage gap F-15). Two authorization servers that share a store can no longer burn each other's codes, refresh tokens or auth_req_ids. A token revoked by one issuer is now recorded under a key naming that issuer.

fix(server)!: digests bound to the issuer

The keys that authorization codes, refresh tokens and CIBA auth_req_ids are stored under didn't include the server's issuer. A token presented to another issuer sharing the store was found, and spent, before ownsRecord refused it.

Each digest is now the SHA-256 of these parts, in order:

  1. a new prefix;
  2. the issuer, length-prefixed;
  3. the existing length-prefixed binding, where there is one;
  4. the value.

Specifically:

  • Codes: fapigo authorization code v2, followed by the issuer, instance key, PKCE challenge, redirect URI, DPoP key and the code.
  • Refresh tokens: fapigo refresh token, followed by the issuer and the token. This was a plain SHA-256.
  • auth_req_ids: fapigo auth_req_id v2, followed by the issuer, instance key, DPoP key and the auth_req_id. Unbound requests are no longer stored under a plain SHA-256.

Code-grant IDs, CIBA grant IDs and grant-registry keys derive from these digests, so they change for new records too.

What breaks on upgrade. UPGRADING.md has a section under v0.85.0, the release this ships in.

  • Every existing refresh token becomes unknown (invalid_grant), so users must authorize again.
  • In-flight codes and CIBA requests fail once.
  • A code issued before the upgrade and reused after it is unknown rather than reused, so it no longer revokes its tokens.
  • Old registry entries stay listable and revocable until they expire.

No code changes are needed; plan the deploy around the forced re-authorization. memstore and sqlstore key records by whatever the server passes, so they need no change. Two sqlstore tests that looked tokens up by the plain hash, which made their checks pass vacuously, are fixed in a separate test(sqlstore) commit.

fix(server) and fix(resource): issuer-namespaced revocation keys (dual write)

grantrevocation.AccessTokenKey(issuer, key) gives access-token: followed by the length-prefixed issuer and the key. The length prefix is there because an issuer path may contain @, so the grant: keys' @ separator can't be used here. These keys can't collide with the grant: or code-grant: keys.

  • Writes: a code reuse now revokes under both the namespaced and the raw key. Both are derived from the code record's raw IssuedAccessTokenKey, so records written by older servers revoke both too.
  • Reads: resource.Verify checks the namespaced key first, when the resolver reports an issuer, then the raw one, both singly and in the IsAnyRevoked batch. Older resource servers still find the raw key.
  • Docs: RevocationChecker, RevocationSink and related docs describe both forms, and say the raw form will be dropped in a later release. UPGRADING.md has a note under v0.85.0 for custom sinks or checkers that restrict a key's shape or length.
  • Limit during the transition: while the raw form is still written, one issuer's raw record can still refuse another issuer's token with the same jti.

Conformance: running, since an upgraded server rejects pre-upgrade codes, refresh tokens and auth_req_ids.

Tests

  • Shared-store tests: three tests over a store shared by two issuers. Another issuer's code is left unspent, and its refresh token and auth_req_id aren't found, while the owning issuer still completes each flow.
  • Revocation keys: a resource-server test covers the namespaced, raw-only, other-issuer and no-issuer cases. Updated reuse tests require both writes.
  • Without the fixes: each new test fails.
  • Mutants: nine new ones, plus one re-anchored, all killed. srv-code-digest-redirect-uri is still killed too.
  • Suites: the full race suite passes, as do sqlstore (including PostgreSQL) and every example module.

🤖 Generated with Claude Code

@codecov

codecov Bot commented Nov 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@osanderson
osanderson force-pushed the fix/issuer-separated-keys branch 2 times, most recently from 811a9f4 to 3dc36f6 Compare November 25, 2026 12:37
osanderson and others added 7 commits November 25, 2026 21:36
… issuer

The digests an authorization code, a refresh token and a CIBA
auth_req_id are stored under (NewAuthorizationCode.CodeHash,
NewRefreshToken.TokenHash, NewBackchannelAuthentication.AuthReqIDHash)
did not include the server's issuer. Two servers of different issuers
sharing one store found each other's records, and the store spent a
code or a CIBA approval, or reported a code reused and so revoked what
it had issued, before the server refused the record as another
issuer's. A client of one issuer could therefore burn a code or
auth_req_id the other had issued.

Each digest is now the SHA-256 of a domain-separation prefix, the
length-prefixed issuer, the existing length-prefixed binding where
there is one, and the value:

- codes: "fapigo authorization code v2" (new prefix), issuer, instance
  key, PKCE challenge, redirect URI, DPoP key, code;
- refresh tokens: "fapigo refresh token", issuer, token (was the plain
  SHA-256 of the token);
- auth_req_ids: "fapigo auth_req_id v2" (new prefix), issuer, instance
  key, DPoP key, auth_req_id. An unbound request is no longer stored
  under the plain SHA-256 of its auth_req_id, so the crafted
  preimage that once shared a bound request's digest no longer does;
  malformed auth_req_ids are still refused before any poll.

A value presented to a server of another issuer sharing the store is
now unknown to the store, and neither found nor consumed. Stores are
unaffected: memstore, sqlstore and custom stores key records by
whatever digest the server passes.

BREAKING CHANGE: every refresh token issued before the upgrade is
unknown afterwards and refused, so clients must re-authorize to get
a new one. Authorization codes and CIBA requests
in flight at deploy fail once. No code changes are needed; plan the
deploy around the forced re-authorization. UPGRADING.md has the
details.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The server now stores a refresh token under a digest of a prefix, its
issuer and the token rather than the plain SHA-256 of the token. Two
server-flow tests looked an issued refresh token up in the store
under the plain digest, so their "the token is gone" checks passed
whatever the store did. They now derive the server's digest, and the
revoked-grant test first checks the token is found under it before
revoking.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
When an authorization code is reused, the server revoked the access
token first issued from it under that token's own key alone: a JWT's
jti, or an opaque token's hex SHA-256. That key carries no issuer, so
with servers of different issuers sharing one revocation store, one
issuer's revoked jti also refused another issuer's token with the
same jti.

The server now writes two revocation records for that token: the key
namespaced by its issuer, "access-token:" then the issuer's length in
bytes, ":", the issuer and the key (grantrevocation.AccessTokenKey),
whose prefix keeps it apart from the "grant:" and "code-grant:" keys,
and, during a transition, the raw key as before, so resource servers
not yet upgraded and checkers that know only the raw form still
refuse the token. The code record still stores the raw key
(IssuedAccessTokenKey); both forms are derived from it at reuse, so
records written by older servers revoke both forms too.

Stored data: one more revocation record per reused code, under the
new key form; nothing else changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Verify checked a token's own revocation key only in its raw form (a
JWT's jti, an opaque token's hex hash). The server now also revokes a
token under that key namespaced by its issuer, so a revocation one
issuer records for a jti doesn't refuse another issuer's token
sharing the store.

Verify now asks about the namespaced key first, when the resolver
reports the token's issuer, then the raw key, so a revocation an
older server wrote still refuses the token. Both go in the same
IsAnyRevoked batch for a store that has it (six keys at most now). A
resolver reporting no issuer is checked under the raw key alone. The
RevocationChecker docs describe both forms and that the raw one will
be dropped in a later release, and UPGRADING.md says what a custom
sink or checker must accept.

Stored data: none; this only adds a lookup.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Covers the issuer in the authorization code, refresh token and
auth_req_id digests, the issuer-namespaced and raw access token
revocation keys the server writes on code reuse and the resource
server checks (one at a time and in a batch), and the length prefix
that splits a namespaced key one way only. Re-anchors the existing
srv-code-reuse-audit-access-token-failure mutant on the reuse
revocation loop that replaced the single Revoke call it targeted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The revoked-grant and registry race tests looked an issued refresh
token up under the issuer-bound digest only. sqlstore's tests also run
against the fapigo release its go.mod requires, which still stores the
plain SHA-256, so there the setup check failed. They now look a token
up under both digests, newest first, so they hold against either
release; the setup check still requires the token to be found before
its removal is checked.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
They ship in the release after 0.84.0: the namespaced revocation key
joins the issuer-bound digests under their own heading.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@osanderson
osanderson force-pushed the fix/issuer-separated-keys branch from 3dc36f6 to 26a1b16 Compare November 25, 2026 13:39
@sonarqubecloud

Copy link
Copy Markdown

@osanderson
osanderson merged commit 280622d into main Nov 25, 2026
34 checks passed
@osanderson
osanderson deleted the fix/issuer-separated-keys branch November 25, 2026 14:05
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