Skip to content

fix(api): Check token expiration in OAuth userinfo endpoint#108465

Merged
dcramer merged 1 commit intomasterfrom
fix/oauth-userinfo-token-expiration
Feb 18, 2026
Merged

fix(api): Check token expiration in OAuth userinfo endpoint#108465
dcramer merged 1 commit intomasterfrom
fix/oauth-userinfo-token-expiration

Conversation

@dcramer
Copy link
Copy Markdown
Member

@dcramer dcramer commented Feb 18, 2026

The OAuthUserInfoEndpoint bypasses standard DRF authentication (authentication_classes = ()) and performs manual token lookup via ApiToken.objects.get(). However, it never calls token.is_expired(), meaning expired OAuth tokens can be used to retrieve user information (user ID, name, email, avatar) indefinitely after the 30-day expiration.

The standard auth pipeline in UserAuthTokenAuthentication.authenticate_token() properly checks is_expired() and rejects expired tokens. This fix adds the same check to the manual token lookup path, returning invalid_token per RFC 6750 Section 3.1.

The OAuthUserInfoEndpoint bypasses standard authentication and performs
manual token lookup via ApiToken.objects.get(), but never checks
is_expired(). This allows expired OAuth tokens to retrieve user
information indefinitely. The standard auth path in
UserAuthTokenAuthentication properly checks token expiration.

Add is_expired() check after token lookup, consistent with the standard
authentication pipeline.

Co-Authored-By: Claude <[email protected]>
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Feb 18, 2026
@dcramer dcramer marked this pull request as ready for review February 18, 2026 18:32
@dcramer dcramer requested a review from a team as a code owner February 18, 2026 18:32
Copy link
Copy Markdown
Contributor

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

raise BearerTokenInvalid()

if token_details.is_expired():
raise BearerTokenInvalid()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Misleading error description for expired tokens

Low Severity

When an expired token is rejected, BearerTokenInvalid returns an error_description of "Access token not found", which is inaccurate — the token was found but is expired. This misleading message could confuse OAuth clients trying to diagnose authentication failures or decide whether to attempt a token refresh. The error code invalid_token is correct per RFC 6750, but the description doesn't match the actual reason for rejection.

Fix in Cursor Fix in Web

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will fix in post

@dcramer dcramer enabled auto-merge (squash) February 18, 2026 18:42
@dcramer dcramer merged commit f039a45 into master Feb 18, 2026
78 checks passed
@dcramer dcramer deleted the fix/oauth-userinfo-token-expiration branch February 18, 2026 18:53
JonasBa pushed a commit that referenced this pull request Feb 19, 2026
The `OAuthUserInfoEndpoint` bypasses standard DRF authentication
(`authentication_classes = ()`) and performs manual token lookup via
`ApiToken.objects.get()`. However, it never calls `token.is_expired()`,
meaning expired OAuth tokens can be used to retrieve user information
(user ID, name, email, avatar) indefinitely after the 30-day expiration.

The standard auth pipeline in
`UserAuthTokenAuthentication.authenticate_token()` properly checks
`is_expired()` and rejects expired tokens. This fix adds the same check
to the manual token lookup path, returning `invalid_token` per RFC 6750
Section 3.1.

Co-authored-by: Claude <[email protected]>
mchen-sentry pushed a commit that referenced this pull request Feb 24, 2026
The `OAuthUserInfoEndpoint` bypasses standard DRF authentication
(`authentication_classes = ()`) and performs manual token lookup via
`ApiToken.objects.get()`. However, it never calls `token.is_expired()`,
meaning expired OAuth tokens can be used to retrieve user information
(user ID, name, email, avatar) indefinitely after the 30-day expiration.

The standard auth pipeline in
`UserAuthTokenAuthentication.authenticate_token()` properly checks
`is_expired()` and rejects expired tokens. This fix adds the same check
to the manual token lookup path, returning `invalid_token` per RFC 6750
Section 3.1.

Co-authored-by: Claude <[email protected]>
@github-actions github-actions bot locked and limited conversation to collaborators Mar 6, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

claude-code-assisted Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants