Skip to content

fix(oauth): drop unused codes in UserRevokeOAuthGrant - #2950

Open
hsusul wants to merge 2 commits into
supabase:masterfrom
hsusul:fix/oauth-revoke-unused-authorization-codes
Open

hsusul wants to merge 2 commits into
supabase:masterfrom
hsusul:fix/oauth-revoke-unused-authorization-codes

Conversation

@hsusul

@hsusul hsusul commented Nov 21, 2026

Copy link
Copy Markdown

Why

Disconnecting an OAuth client left an authorization code issued before the revoke exchangeable. The client received a new access token and refresh token after it no longer appeared in the user's grants. Fixes #2942.

What changed

UserRevokeOAuthGrant deletes that user's approved oauth_authorizations rows for the client before it deletes sessions. POST /oauth/token then returns invalid_grant for those codes.

Scope

UserRevokeOAuthGrant, DeleteApprovedOAuthServerAuthorizations, and TestRevokeOAuthGrantRejectsUnexchangedCode.

Tradeoffs

Pending authorizations stay. An open consent screen can still be approved and create a new grant. A second consent check inside token exchange is unnecessary once the approved row is gone.

Blast Radius

The delete is limited to one user and one client. Other clients, other users, and pending authorizations are unchanged.

Verification

Before the fix, TestRevokeOAuthGrantRejectsUnexchangedCode failed with An error is expected but got nil. A second authorization_code login was logged after token_revoked.

After the fix, this passed:

go test -count=1 -race -timeout 180s -run TestOAuthClientHandler ./internal/api/oauthserver/

That includes TestRevokeOAuthGrantRejectsUnexchangedCode and TestUserRevokeOAuthGrant.

A separate run held the authorization row during exchange. Revoke returned 204 only after that new session was gone, and a later exchange of the same code returned invalid_grant.

DELETE /user/oauth/grants removes the consent and its sessions. An
authorization code issued before that call still returns tokens.
…oked

The token endpoint redeems the approved authorization row. Delete those
rows for the user and client in the revoke transaction before deleting
sessions, so a code issued before the revoke cannot mint a new session.
@hsusul
hsusul requested a review from a team as a code owner November 21, 2026 06:28

This branch has not been deployed

No deployments
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.

OAuth 2.1 server: authorization codes issued before a grant is revoked can still be exchanged for tokens

1 participant