CVE-2022-31127
JSON

7.1high

Improper handling of email input in next-auth

Severity
7.1high CVSS:3.1 by GitHub_M
Exploit likelihood
1.15% (higher than 67% of CVEs; EPSS, by FIRST)
Published
Last changed
Assigned by
GitHub_M
Also known as
GHSA-pgjx-7f9g-9463

Description

NextAuth.js is a complete open source authentication solution for Next.js applications. An attacker can pass a compromised input to the e-mail [signin endpoint](https://next-auth.js.org/getting-started/rest-api#post-apiauthsigninprovider) that contains some malicious HTML, tricking the e-mail server to send it to the user, so they can perform a phishing attack. Eg.: `balazs@email.com, <a href="http://attacker.com">Before signing in, claim your money!</a>`. This was previously sent to `balazs@email.com`, and the content of the email containing a link to the attacker's site was rendered in the HTML. This has been remedied in the following releases, by simply not rendering that e-mail in the HTML, since it should be obvious to the receiver what e-mail they used: next-auth v3 users before version 3.29.8 are impacted. (We recommend upgrading to v4, as v3 is considered unmaintained. next-auth v4 users before version 4.9.0 are impacted. If for some reason you cannot upgrade, the workaround requires you to sanitize the `email` parameter that is passed to `sendVerificationRequest` and rendered in the HTML. If you haven't created a custom `sendVerificationRequest`, you only need to upgrade. Otherwise, make sure to either exclude `email` from the HTML body or efficiently sanitize it.

Affected

Product or packageVersionsReported by
nextauthjs next-auth< 3.29.8, >= 4.0.0, < 4.9.0CVE List
next-auth (npm)before 3.29.8, from 4.0.0 before 4.9.0GitHub Advisory Database
nextauth.js next-authbefore 3.29.8, from 4.0.0 before 4.9.0NVD

All scores

GitHub_M7.1high CVSS:3.1CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:L/I:L/A:L
GitHub7.1high CVSS:3.1CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:L/I:L/A:L
NVD6.1medium CVSS:3.1CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:L/I:L/A:N
NVD4.3medium CVSS:2.0AV:N/AC:M/Au:N/C:N/I:P/A:N

Classification

CWE-79

SSVC (CISA-ADP): exploitation poc, automatable no, technical impact partial.

What each source says

CVE List

NextAuth.js is a complete open source authentication solution for Next.js applications. An attacker can pass a compromised input to the e-mail [signin endpoint](https://next-auth.js.org/getting-started/rest-api#post-apiauthsigninprovider) that contains some malicious HTML, tricking the e-mail server to send it to the user, so they can perform a phishing attack. Eg.: `balazs@email.com, <a href="http://attacker.com">Before signing in, claim your money!</a>`. This was previously sent to `balazs@email.com`, and the content of the email containing a link to the attacker's site was rendered in the HTML. This has been remedied in the following releases, by simply not rendering that e-mail in the HTML, since it should be obvious to the receiver what e-mail they used: next-auth v3 users before version 3.29.8 are impacted. (We recommend upgrading to v4, as v3 is considered unmaintained. next-auth v4 users before version 4.9.0 are impacted. If for some reason you cannot upgrade, the workaround requires you to sanitize the `email` parameter that is passed to `sendVerificationRequest` and rendered in the HTML. If you haven't created a custom `sendVerificationRequest`, you only need to upgrade. Otherwise, make sure to either exclude `email` from the HTML body or efficiently sanitize it.

GitHub Advisory Database
Impact

An attacker can pass a compromised input to the e-mail signin endpoint that contains some malicious HTML, tricking the e-mail server to send it to the user, so they can perform a phishing attack. Eg.: balazs@email.com, <a href="http://attacker.com">Before signing in, claim your money!</a>. This was previously sent to balazs@email.com, and the content of the email containing a link to the attacker's site was rendered in the HTML. This has been remedied in the following releases, by simply not rendering that e-mail in the HTML, since it should be obvious to the receiver what e-mail they used:

next-auth v3 users before version 3.29.8 are impacted. (We recommend upgrading to v4, as v3 is considered unmaintained. See our migration guide)

next-auth v4 users before version 4.8.0 are impacted.

Patches

We've released patches for this vulnerability in:

  • v3 - 3.29.8
  • v4 - 4.9.0

You can do:

npm i next-auth@latest
# or
yarn add next-auth@latest
#
pnpm add next-auth@latest

(This will update to the latest v4 version, but you can change latest to 3 if you want to stay on v3. This is not recommended.)

Workarounds

If for some reason you cannot upgrade, the workaround requires you to sanitize the email parameter that is passed to sendVerificationRequest and rendered in the HTML. If you haven't created a custom sendVerificationRequest, you only need to upgrade. Otherwise, make sure to either exclude email from the HTML body or efficiently sanitize it. Check out https://next-auth.js.org/providers/email#customizing-emails

References

Related documentation:

A test case has been added so this kind of issue will be checked before publishing. See: https://github.com/nextauthjs/next-auth/blob/cd6ccfde898037290ae949d500ace8a378376cd8/packages/next-auth/tests/email.test.ts

For more information

If you have any concerns, we request responsible disclosure, outlined here: https://next-auth.js.org/security#reporting-a-vulnerability

Timeline

The issue was reported 2022 June 29th, a response was sent out to the reporter in less than 1 hour, and after identifying the issue a patch was published within 4 working days.

NVD (es)

NextAuth.js es una completa solución de autenticación de código abierto para aplicaciones Next.js. Un atacante puede pasar una entrada comprometida al correo electrónico [signin endpoint](https://next-auth.js.org/getting-started/rest-api#post-apiauthsigninprovider) que contiene algún HTML malicioso, engañando al servidor de correo electrónico para que lo envíe al usuario, y así poder llevar a cabo un ataque de phishing. Eg.: "balazs@email.com, (a href="http://attacker.com")Before signing in, claim your money!(/a)". Anteriormente era enviado a "balazs@email.com", y el contenido del correo electrónico que contenía un enlace al sitio del atacante era renderizado en el HTML. Esto ha sido mitigado en las siguientes versiones, simplemente no renderizando ese correo electrónico en el HTML, ya que debería ser obvio para el receptor qué correo electrónico fue usado: los usuarios de next-auth versiones v3 anteriores a 3.29.8 están afectados. (Recomendamos actualizar a la versión v4, ya que la versión v3 es considerada sin mantenimiento. Los usuarios de next-auth versiones v4 anteriores a 4.9.0 están afectados. Si por alguna razón no puedes actualizar, la mitigación requiere que sea saneado el parámetro "email" que es pasado a "sendVerificationRequest" y es mostrado en el HTML. Si no has creado un "sendVerificationRequest" personalizado, sólo tienes que actualizar. En caso contrario, asegúrese de excluir "email" del cuerpo del HTML o de sanearlo eficazmente

References

Sources

SourceRecordLicence
CVE ListCVE-2022-31127 changed 2025-04-22CVE Terms of Use
GitHub Advisory DatabaseGHSA-pgjx-7f9g-9463 changed 2023-11-08CC-BY-4.0
NVDCVE-2022-31127 changed 2026-06-17Public domain