Missing proper state, nonce and PKCE checks for OAuth authentication
Impact
next-auth applications using OAuth provider versions before v4.20.1 are affected.
A bad actor who can spy on the victim's network or able to social engineer the victim to click a manipulated login link could intercept and tamper with the authorization URL to log in as the victim, bypassing the CSRF protection.
As an example, an attack can happen in the following scenario.
TL;DR: The attacker steals the victim's authenticated callback by intercepting and tampering with the authorization URL created by
next-auth.
-
The victim attempts to log in to the
next-authsite. For example https://next-auth-example.vercel.app/ -
next-authsets thecheckscookies according to how the OAuth provider is configured. In this case,stateandpkceare set by default for the Google Provider. <img width="1971" alt="Screen Shot 2023-03-03 at 09 54 26" src="https://user-images.githubusercontent.com/31528554/222619750-a2062bb8-99eb-4985-a75c-d75acd3da67e.png"> -
The attacker intercepts the returned authorization URL, strips away the OAuth check (nonce, state, pkce), and returns the URL without the check to the victim's browser. For example: From
https://accounts.google.com/o/oauth2/v2/auth/oauthchooseaccount?client_id=client_id&scope=openid%20email%20profile&response_type=code&redirect_uri=https%3A%2F%2Fnext-auth-example.vercel.app%2Fapi%2Fauth%2Fcallback%2Fgoogle&state=state&code_challenge=code_challenge&code_challenge_method=S256&service=lso&o2v=2&flowName=GeneralOAuthFlowtohttps://accounts.google.com/o/oauth2/v2/auth/oauthchooseaccount?client_id=client_id&scope=openid%20email%20profile&response_type=code&redirect_uri=https%3A%2F%2Fnext-auth-example.vercel.app%2Fapi%2Fauth%2Fcallback%2Fgoogle&service=lso&o2v=2&flowName=GeneralOAuthFlow. Notice the parametersstate,code_challengeandcode_verifierare removed from the victim's address bar. -
The victim attempts to log in using their OAuth account.
-
The Authorization Server logs the victim in and calls back to the
next-authapi/auth/callback/:providerIdendpoint. 5.1. The attacker intercepts and logs this callback URL for later use. 5.2.next-authchecks the callback call from OAuth Authorization Server (doesn't have checks) and compares the checks with the cookies set (has checks) at step 2. This check will fail, resulting in the victim isn't logged in. However, at this step, the Authorization Server has already accepted the victim's request to log in and generated/sent acodein the URL. -
The attacker now has an authorization URL with the
codethat the AS will exchange for validaccess_token/id_tokenand can log in as the victim automatically. They can open a new browser window and paste in the URL logged at step 5.1 and log in as the victim.
Patches
We patched the vulnerability in next-auth v4.20.1
To upgrade, run one of the following:
npm i next-auth@latest
yarn add next-auth@latest
pnpm add next-auth@latest
Workarounds
Upgrading to latest is the recommended way to fix this issue. However, using Advanced Initialization, developers can manually check the callback request for state, pkce, and nonce against the provider configuration, and abort the sign-in process if there is a mismatch. Check out the source code for help.
References
Software afectado
Haz clic en una tecnología para ver todas sus vulnerabilidades.
| Plataforma | Paquete | Versiones vulnerables | Corregida en |
|---|---|---|---|
| Paquete de npm | next-auth | < 4.20.1 | 4.20.1 |
Referencias
- https://github.com/nextauthjs/next-auth/security/advisories/GHSA-7r7x-4c4q-c4qf
- https://nvd.nist.gov/vuln/detail/CVE-2023-27490
- https://authjs.dev/reference/core/providers#checks
- https://danielfett.de/2020/05/16/pkce-vs-nonce-equivalent-or-not
- https://github.com/nextauthjs/next-auth
- https://github.com/nextauthjs/next-auth/compare/next-auth@4.20.0...next-auth@4.20.1#diff-cf9257195d0cb6a835ae4ff1fc73fe2cac0bab847efb0832c1f551209a972b47R55
- https://next-auth.js.org/configuration/initialization#advanced-initialization
- https://next-auth.js.org/configuration/providers/oauth
- https://security.netapp.com/advisory/ntap-20230420-0006
- https://www.rfc-editor.org/rfc/rfc6749#section-10.12
- Vector CVSS
CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:N- Debilidad (CWE)
CWE-352- Plataforma
- npm
- Paquete
next-auth- Publicada
- 13.03.2023
- Actualizado
- 11.10.2026 10:22
Fuentes y licencias
OSV / GitHub Advisory Database - GHSA-7r7x-4c4q-c4qf - CC BY 4.0
Historial de vulnerabilidades: next-auth
Todas las vulnerabilidades publicadas de este paquete (Paquete de npm), de la más reciente a la más antigua. Muestra si es un fallo aislado o un paquete que hay que vigilar.
- Entradas en total
- 14
- Primera → última
- 02.2021 07.2026
- Sin corrección
- 0
- Explotada en ataques
- 0
Distribución por gravedad
- Crítica 3
- Alta 4
- Media 5
- Baja 2
Divulgaciones por año
- 2021: 1
- 2022: 6
- 2023: 2
- 2024: 0
- 2025: 1
- 2026: 4
-
Missing proper state, nonce and PKCE checks for OAuth authentication esta entrada
Identifica las vulnerabilidades de tu aplicación
Con la integración de DockRay y el inventario de software activado, DockRay compara las versiones notificadas de los componentes con las vulnerabilidades conocidas y avisa de las coincidencias confirmadas. La cobertura depende de la tecnología compatible y de los avisos disponibles.