Skip to content

Refresh token revoked before scope validation #390

@runeb

Description

@runeb

Specify your setup

  • Operating System: Linux (Debian 12.12)
  • Node version: 24.12.0
  • npm version: N/A (using pnpm)
  • version of @node-oauth/oauth2-server: 5.2.0
  • which OAuth2 workflow: Refresh Token Grant (RFC 6749 Section 6)
  • at which workflow step: Token refresh with scope parameter

Describe the bug

When refreshing a token with invalid scopes, the refresh token is revoked before scope validation. If validation fails, the token is destroyed without creating a replacement, permanently breaking authentication.

To Reproduce

  1. Issue refresh token without scope
  2. Client requests refresh with scope=some-scope
  3. revokeToken() destroys the token (line 57)
  4. getScope() throws InvalidScopeError (line 59)
  5. Client retries without scope
  6. Receives "Invalid grant: refresh token is invalid"

Expected behavior

Scope validation should occur before revocation. Invalid scope requests should fail without destroying the token.

Additional context

The fix is to swap lines 57 and 59 in lib/grant-types/refresh-token-grant-type.js to validate scope before revoking. Similar to issue #82 which addressed authorization code revocation timing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions