The vulnerability exists because the OAuth anti-CSRF cookies (state, nonce, and PKCE verifier) were not bound to the specific OAuth provider that initiated the authentication flow. The cookies were stored globally, meaning a cookie generated during a sign-in attempt with one provider could be used in the callback of a different provider. This could lead to a provider-confusion or mix-up attack.
The patches address this by adding the provider.id to the cookie's payload when it is created (in signCookie for next-auth and sealCookie for @auth/core). Subsequently, when the cookie is consumed (in pkce.use, state.use, nonce.use for next-auth and parseCookie for @auth/core), a check is added to ensure the provider.id in the cookie matches the ID of the provider handling the callback. If they do not match, an error is thrown, preventing the attack.
The identified vulnerable functions are the ones responsible for consuming and validating these cookies, as they were missing the crucial provider verification step. An attacker could exploit this by tricking a user into initiating an authentication flow with a malicious or compromised provider, capturing the anti-CSRF cookie, and then using it to link their own account to the victim's account on a different, legitimate provider within the same application.