Skip to content

Refresh grant guard skips its recheck when the client disconnects #7312

Backlog

Description

@jhrozek

Bug description

When the embedded auth server's upstream refresh guard sees the IdP reject an upstream refresh with invalid_grant, it waits 500ms, re-reads the row, and only then refuses the refresh grant and deletes the session's upstream rows. If the client's request context ends during that wait, rejectionConfirmed (pkg/authserver/refresh_grant_guard.go) returns false ("recheck cancelled; not refusing") and checkRow treats the outcome as uncertain. Nothing is deleted.

A holder of a valid ToolHive refresh token whose upstream credential is dead can therefore send a refresh grant and disconnect within the recheck window, again and again. The guard's refresh runs in a detached goroutine, so each attempt still makes one upstream IdP call, and the session is never dropped, so the next attempt does the same.

This is how the guard has behaved since it was added. It came up in review of "Stop re-sending upstream refresh tokens the IdP rejected" (#7307), where the guard skips the new rejection memory and so no longer absorbs these calls.

Steps to reproduce

  1. Sign in through the embedded auth server so a session holds an upstream refresh token.
  2. Make that upstream refresh token invalid at the IdP (revoke it), and let the stored upstream access token expire.
  3. Send a refresh_token grant to /oauth/token and close the connection about 100ms later, before the 500ms recheck finishes.
  4. Repeat step 3.

Expected behavior

Once the IdP has rejected the refresh, the guard finishes its recheck and, if the rejection is confirmed, deletes the session's upstream rows, even if the client has gone. Later attempts are then refused as having no rows, without an IdP call.

Actual behavior

Each attempt makes one upstream IdP call, logs "refresh grant guard recheck cancelled; not refusing" at DEBUG, and deletes nothing.

Additional context

A possible fix: after a rejection that came from the IdP, run the recheck and dropSession detached from the request context, with their own timeout, so a disconnect no longer skips them. This changes the current rule that a client disconnect never refuses a session that may be live, so the race the recheck exists for (another replica's refresh landing during the wait) has to stay covered.

Activity

  1. added
    bug
    on Nov 25, 2026
  2. added
    needs-triage
    on Nov 25, 2026
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

    bugneeds-triage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions