The vulnerability is a race condition in the refresh token rotation and revocation process within the @better-auth/oauth-provider package. The root cause is a time-of-check to time-of-use (TOCTOU) flaw where the application checks if a refresh token is revoked and then proceeds to use it without any locking mechanism. This allows two concurrent requests with the same refresh token to both pass the revocation check before either one can mark the token as revoked, resulting in the issuance of multiple new refresh tokens (a "forked family").
The analysis of the patch commit c6918ecc9e3a75892169415d7f6c95b591b6a52d clearly shows the vulnerable functions and the fix. The functions createRefreshToken and revokeRefreshToken were modified to use an atomic compare-and-swap (CAS) operation. This is achieved by adding revoked: null to the where clause of the update operation, ensuring that the update only succeeds if the token has not been revoked by another process in the meantime. The handleRefreshTokenGrant function, which is the entry point for the refresh token grant, was also updated to use the new invalidateRefreshFamily function to clean up tokens when a replay is detected.
Therefore, the vulnerable functions that would appear in a runtime profile during exploitation are handleRefreshTokenGrant, createRefreshToken, and revokeRefreshToken.