# CVE-2022-31127: Improper handling of email input in next-auth

> Attackers can inject malicious HTML into verification emails via the email input, enabling phishing attacks against users of NextAuth.js.

- **Severity:** High 7.1 (`CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:L/I:L/A:L`)
- **Exploited in the wild:** Not known
- **Login needed:** Not needed
- **Attackable:** Over the internet
- **Victim action needed:** A user has to click or open something
- **Fix available:** Yes
- **Published:** 6 Jul 2022
- **Updated:** 22 Apr 2025
- **Also known as:** GHSA-pgjx-7f9g-9463

## What is CVE-2022-31127?

CVE-2022-31127 is a high-severity cross-site scripting vulnerability in nextauthjs next-auth, published on 6 Jul 2022. An attacker can exploit it over the internet without logging in, and only if a user opens a file or follows a link.

### Official 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.

Weakness: CWE-79 (Improper Neutralization of Input During Web Page Generation)

## Which versions are affected by CVE-2022-31127?

4 open source packages ship an affected version, including next-auth. It affects 1 product.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `next-auth` | npm | All versions | 3.29.8 |
| `next-auth` | npm | All versions | 3.29.8 |
| `next-auth` | npm | From 4.0.0 | 4.9.0 |
| `next-auth` | npm | From 4.0.0 | 4.9.0 |

Products: Nextauth.js Next-Auth.

## How do I fix CVE-2022-31127?

Upgrade next-auth to a fixed version for your release line: 3.29.8 or 4.9.0.

## Is CVE-2022-31127 being exploited?

It is not confirmed as exploited in the wild, but public exploit code for CVE-2022-31127 exists.

## Other vulnerabilities in nextauthjs next-auth

- [CVE-2022-35924](https://insights.sbomify.com/CVE-2022-35924/): Verification requests (magic link) sent to unwanted emails (critical 9.1)
- [CVE-2023-27490](https://insights.sbomify.com/CVE-2023-27490/): Missing proper state, nonce and PKCE checks for OAuth authentication in next-auth (high 8.1)
- [CVE-2022-31093](https://insights.sbomify.com/CVE-2022-31093/): Improper Handling of `callbackUrl` parameter in next-auth (high 7.5)
- [CVE-2022-39263](https://insights.sbomify.com/CVE-2022-39263/): NextAuth.js Upstash Adapter missing token verification (medium 6.8)
- [CVE-2022-29214](https://insights.sbomify.com/CVE-2022-29214/): URL Redirection to Untrusted Site ('Open Redirect') in next-auth (medium 6.1)

## Fix prompt for AI coding agents

```text
Check this codebase for CVE-2022-31127 and fix it if it is affected.

What it is: CVE-2022-31127 is a high-severity cross-site scripting vulnerability in nextauthjs next-auth, published on 6 Jul 2022. An attacker can exploit it over the internet without logging in, and only if a user opens a file or follows a link.
Exploitation: It is not confirmed as exploited in the wild, but public exploit code for CVE-2022-31127 exists.

Affected packages and fixed versions:
- next-auth (npm): affected all versions; fixed in 3.29.8
- next-auth (npm): affected all versions; fixed in 3.29.8
- next-auth (npm): affected from 4.0.0; fixed in 4.9.0
- next-auth (npm): affected from 4.0.0; fixed in 4.9.0

Task:
1. Search the dependency manifests and lockfiles (for example package.json, package-lock.json, requirements.txt, poetry.lock, uv.lock, pom.xml, build.gradle, go.mod, Cargo.lock, Gemfile.lock) and any Dockerfiles for the affected packages, including transitive dependencies.
2. If an affected version is in use, upgrade it to the fixed version for its release line with the project's package manager, so the lockfile is regenerated. Prefer the smallest upgrade that fixes it.
3. If there is no fix, or the upgrade would break the build, do not guess: explain the risk and the safest workaround instead.
4. Run the tests and summarise what changed and why.
5. If nothing in the project is affected, say so and change nothing.

Reference: https://insights.sbomify.com/CVE-2022-31127/ (Markdown: https://insights.sbomify.com/CVE-2022-31127/index.md)
```

## Sources

- CVE record: https://www.cve.org/CVERecord?id=CVE-2022-31127
- NVD: https://nvd.nist.gov/vuln/detail/CVE-2022-31127
- OSV: https://osv.dev/vulnerability/CVE-2022-31127

---
From sbomify Insights: https://insights.sbomify.com/CVE-2022-31127/
Summaries are generated and may contain mistakes; the official description above is the record.
