The vulnerability is a Cross-Site Request Forgery (CSRF) in the OAuth flow of fastapi-users. The root cause is the use of a stateless state parameter in the OAuth 2.0 authorization process. The state parameter, implemented as a JWT, did not contain any per-session or per-request data to link it to the browser session that initiated the login flow.
The analysis of the patch commit 7cf413cd766b9cb0ab323ce424ddab2c0d235932 reveals that the authorize functions in both get_oauth_router and get_oauth_associate_router were modified to generate a CSRF token. This token is included in the state JWT and also sent to the client as a secure, HTTP-only cookie (a 'double-submit cookie').
Consequently, the corresponding callback functions were updated to validate the state parameter by comparing the CSRF token from the JWT with the one received in the cookie. Before the patch, these callback functions only validated the JWT's signature and expiration, leaving them open to CSRF. An attacker could initiate an OAuth flow, obtain a valid state token, and then trick a victim into using that token to link the attacker's OAuth identity to the victim's account or log the victim into the attacker's account.
The vulnerable functions are the inner authorize and callback functions defined within get_oauth_router and get_oauth_associate_router, as they were responsible for the insecure handling of the OAuth state.