Repository navigation
fix(server): answer invalid_grant for a grant revoked during refresh-token issuance - #985
Merged
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
When a grant was revoked while its refresh token was being stored, typically a reused authorization code racing the exchange that redeemed it, the server withdrew the token but answered server_error (HTTP 500) "failed to issue refresh token". Nothing was issued, but the client saw a store outage for what is a refused grant. Both checks that run after the token is stored now mark that outcome with errGrantRevokedWhileIssued: confirmGrantNotRevoked when the revocation check finds the grant revoked, and confirmGrantRecorded when the grant registry no longer lists it. A new refreshTokenIssueFailure maps it to invalid_grant (HTTP 400) "the grant has been revoked" for the authorization code exchange, the CIBA token request and IssueRefreshToken alike, so their audit events record invalid_grant too. Everything else stays server_error: a revocation store or registry that can't answer, and a revoked grant whose token then can't be withdrawn (withdrawRefreshToken now marks that failure), since a live token may remain. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…race A code exchange whose grant a racing reuse revokes while it stores its refresh token now answers invalid_grant rather than server_error. The race tests accept that answer, and TestServerCodeReuseRacingIssuanceIsInvalidGrant is no longer skipped. The server_error shapes FAPIgo answered before are still accepted, but only when the tests are built against a released FAPIgo rather than the tree beside this module (go.mod's replace dropped, as CI's run against the required release does), since that release may predate the change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Covers the mapping of a grant revoked while its refresh token was issued to invalid_grant, server_error for a store failure or a token that couldn't be withdrawn, and each token path's use of it. Updates the anchors of three existing mutants on the code it changed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
osanderson
force-pushed
the
fix/race-invalid-grant
branch
from
November 25, 2026 15:14
80118ad to
a0575f7
Compare
…token The server now answers a grant revoked while its refresh token is issued with invalid_grant, so a code exchange whose grant was revoked before redemption is refused with the same code whether the check before issuance or the re-check after it refuses it. The test of the check before issuance asked for a refresh token, so it no longer told the two apart. This adds the same exchange without offline_access, where nothing after redemption re-checks the grant, and runs the check's mutant against it too. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



A token request whose grant is revoked while the server stores its refresh token now answers
invalid_grant(400) instead ofserver_error(500). Real store failures stayserver_error.Why
When a reused authorization code races the exchange that redeemed it, the reuse revokes the grant. That can happen after the winning exchange has stored its refresh token. The server then re-checks the grant and withdraws the token, so nothing is issued. But the client got a 500, "failed to issue refresh token": a store outage, for what is a refused grant. In concurrent exchanges of one code this was the usual outcome (#966 found it).
fix(server)The issuance failure goes through a new helper,
refreshTokenIssueFailure. It answersinvalid_grant("the grant has been revoked") only when the grant was found revoked meanwhile and its refresh token was withdrawn. Either of the server's two checks can find this:confirmGrantNotRevoked): it now marks only aninvalid_grantit found. A revocation store that can't answer is stillserver_error.confirmGrantRecorded): it finds the grant's registry entry gone.Two cases stay
server_error:withdrawRefreshTokennow marks that failure with its own sentinel, and the helper excludes it.Where it applies: every path that issues a refresh token uses the helper, namely both branches of the authorization code exchange, the CIBA token request, and
Server.IssueRefreshToken.Audit and docs: audit events record the new code, and tests check this.
GETTING_STARTED.mdand UPGRADING.md (under v0.86.0) say a client or monitoring may now see 400 where it saw 500. No exported API changes.test(sqlstore)TestServerCodeReuseRacingIssuanceIsInvalidGrantis no longer skipped. The concurrent-exchange race test now expects losers to answerinvalid_grant.CI also runs sqlstore's tests against the released fapigo its go.mod requires, which still answers
server_error. So the old shapes are accepted only when go.mod has noreplaceof fapigo. Against this tree, the tests are strict.Tests
server_error.invalid_grant.This changes an error code on the wire, so conformance is running.
🤖 Generated with Claude Code