Repository navigation
Description
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
- Sign in through the embedded auth server so a session holds an upstream refresh token.
- Make that upstream refresh token invalid at the IdP (revoke it), and let the stored upstream access token expire.
- Send a
refresh_tokengrant to/oauth/tokenand close the connection about 100ms later, before the 500ms recheck finishes. - 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