Skip to content

Refresh token revoked before scope validation #390

Closed

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.

Activity

  1. jankapunkt commented on Jan 7, 2026

    @jankapunkt
    Member

    Hey @runeb thank you very much for revealing this one. I will review tomorrow, please make sure to update the tests accordingly.

  2. runeb commented on Jan 7, 2026

    @runeb
    ContributorAuthor

    @jankapunkt Thanks for the quick reply, I will add a test for this case

  3. runeb commented on Jan 7, 2026

    @runeb
    ContributorAuthor

    @jankapunkt I didn't find an existing test for testing invalid extra scope in refresh requests, so I made the test more generally about that, with assertions that revoke and save are not called on the model when returning "Invalid scope: Unable to add extra scopes"

  4. jankapunkt commented on Jan 12, 2026

    @jankapunkt
    Member

    Thanks @runeb

  5. added a commit that references this issue on Jan 12, 2026
  6. jankapunkt commented on Jan 12, 2026

    @jankapunkt
    Member

    @runeb this is merged and released in 5.2.2-rc.0 please install via npm i @node-oauth/oauth2-server@5.2.2-rc.0 and let me know if anything unexpectedly breaks.

  7. runeb commented on Jan 14, 2026

    @runeb
    ContributorAuthor

    Thank you @jankapunkt . Our oauth server test suite passes on 5.2.2-rc.0

  8. tlangens commented on Jun 11, 2026

    @tlangens

    @jankapunkt seems like #389 didn't make it into 5.3.0, any reason for that?

  9. dhensby commented on Jun 15, 2026

    @dhensby
    Contributor

    Thanks for the nudge @tlangens — you're right, and here's what happened.

    The fix (#389) was merged into the development branch and released as 5.2.2-rc.0, but development was never merged back into master. 5.3.0 was cut from master, so it shipped without the fix. In the meantime development had fallen ~47 commits behind master, which is why this slipped through.

    I've opened #441, which merges development back into master (preserving @runeb's original commit) and resolves the divergence so the only net change against master is the fix + its test. Full suite passes. Once that lands I'll cut a release and follow up here.

    Leaving this open until #441 is merged and released.

  10. added a commit that references this issue on Jun 16, 2026
  11. tlangens commented on Aug 3, 2026

    @tlangens

    @dhensby did you mean to cut a new release now that #441 is merged?

  12. dhensby commented on Aug 3, 2026

    @dhensby
    Contributor

    I can't make releases, but we should

  13. tlangens commented on Aug 4, 2026

    @tlangens

    @jankapunkt can we have a new release including the missing changes from #441 ?

  14. trevorloranger commented on Sep 30, 2026

    @trevorloranger

    @jankapunkt can we have a new release including the missing changes from #441 ?

    @jankapunkt @dhensby : bumping the above request. Thank you 🙏 cc: @tlangens

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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