Skip to main content

CVE-2022-31127: CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting') in nextauthjs next-auth

Medium
Published: Wed Jul 06 2022 (07/06/2022, 18:00:16 UTC)
Source: CVE
Vendor/Project: nextauthjs
Product: next-auth

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.

AI-Powered Analysis

AILast updated: 06/22/2025, 00:22:39 UTC

Technical Analysis

CVE-2022-31127 is a cross-site scripting (XSS) vulnerability classified under CWE-79 that affects NextAuth.js, an open-source authentication library widely used in Next.js applications. The vulnerability arises from improper neutralization of user input during web page generation, specifically in the email signin endpoint. An attacker can craft a malicious input containing HTML code and inject it into the email parameter sent to the signin endpoint. This malicious input is then included in the HTML content of the verification email sent to the user. For example, an attacker could submit an email value such as `balazs@email.com, <a href=\"http://attacker.com\">Before signing in, claim your money!</a>`. When the email server sends the verification email, the malicious HTML is rendered, potentially tricking the recipient into clicking on attacker-controlled links, facilitating phishing attacks or other social engineering exploits. The vulnerability affects NextAuth.js versions prior to 3.29.8 in the v3 branch and versions from 4.0.0 up to but not including 4.9.0 in the v4 branch. The issue has been addressed by removing the rendering of the email parameter in the HTML content of the verification email. Users who cannot upgrade are advised to sanitize the email parameter in any custom implementations of the sendVerificationRequest function to prevent injection of malicious HTML. This vulnerability does not require authentication or user interaction to be exploited, but the attack relies on the victim receiving and interacting with the phishing email. No known exploits have been reported in the wild as of the publication date. The vulnerability primarily impacts the confidentiality and integrity of users by enabling phishing attacks that could lead to credential theft or further compromise.

Potential Impact

For European organizations, the impact of this vulnerability can be significant, especially for those relying on NextAuth.js for user authentication in web applications. Successful exploitation can lead to phishing attacks that compromise user credentials, potentially resulting in unauthorized access to sensitive systems and data. This can undermine user trust, lead to data breaches, and cause reputational damage. Organizations in sectors with strict data protection regulations, such as finance, healthcare, and government, may face legal and compliance repercussions under GDPR if user data is compromised. Additionally, phishing attacks can serve as a vector for further malware deployment or lateral movement within networks. Since NextAuth.js is popular among developers building modern web applications, the scope of affected systems can be broad, impacting both small and large enterprises. The vulnerability does not directly affect system availability but can indirectly cause service disruptions if exploited at scale or if remediation requires downtime.

Mitigation Recommendations

The primary mitigation is to upgrade NextAuth.js to version 3.29.8 or later in the v3 branch, or to version 4.9.0 or later in the v4 branch, where the vulnerability has been fixed by removing the rendering of the email parameter in the verification email HTML. For organizations unable to upgrade immediately, it is critical to sanitize the email parameter passed to the sendVerificationRequest function to strip or encode any HTML or script content before rendering. If a custom sendVerificationRequest implementation exists, review and modify it to exclude the email parameter from the HTML body or apply robust input sanitization libraries that neutralize XSS payloads. Additionally, organizations should implement email security best practices such as DMARC, DKIM, and SPF to reduce the risk of phishing emails being delivered or trusted. User awareness training focused on recognizing phishing attempts can further reduce the risk of successful exploitation. Monitoring email logs and application logs for unusual or malformed email parameters can help detect attempted exploitation. Finally, applying Content Security Policy (CSP) headers in web applications can mitigate the impact of XSS attacks by restricting the execution of unauthorized scripts.

Need more detailed analysis?Get Pro

Technical Details

Data Version
5.1
Assigner Short Name
GitHub_M
Date Reserved
2022-05-18T00:00:00.000Z
Cisa Enriched
true

Threat ID: 682d9849c4522896dcbf668e

Added to database: 5/21/2025, 9:09:29 AM

Last enriched: 6/22/2025, 12:22:39 AM

Last updated: 8/14/2025, 11:52:46 PM

Views: 13

Actions

PRO

Updates to AI analysis are available only with a Pro account. Contact root@offseq.com for access.

Please log in to the Console to use AI analysis features.

Need enhanced features?

Contact root@offseq.com for Pro access with improved analysis and higher rate limits.

Latest Threats