GHSA-5jpx-9hw9-2fx4: NextAuthjs Email misdelivery Vulnerability
N/A
Basic Information
Technical Details
| Package Name | Ecosystem | Vulnerable Versions | First Patched Version |
|---|---|---|---|
| next-auth | npm | < 4.24.12 | 4.24.12 |
| next-auth | npm | >= 5.0.0-beta.0, < 5.0.0-beta.30 | 5.0.0-beta.30 |
Vulnerability Intelligence
Miggo AI
Root Cause Analysis
The vulnerability exists in how the next-auth library handles email addresses for authentication, specifically due to a parsing flaw in its dependency, nodemailer (versions prior to 7.0.7). An attacker could craft a malicious email address string such as "e@attacker.com"@victim.com. The vulnerable code in next-auth would fail to properly sanitize this input before passing it to nodemailer. The vulnerable version of nodemailer would then incorrectly parse this string, leading to the authentication email being sent to the attacker's address (e@attacker.com) instead of the legitimate user's domain (victim.com).
The analysis of the patches reveals two key locations where this vulnerability is addressed. The first is within the signin function in packages/next-auth/src/core/routes/signin.ts. The second is within the defaultNormalizer function, which is called by the sendToken function in packages/core/src/lib/actions/signin/send-token.ts. In both cases, the patches introduce stricter validation for email addresses, specifically checking for and rejecting formats that include quotes or multiple '@' symbols, which are characteristic of this exploit. The patches also update the nodemailer dependency to a non-vulnerable version as the primary mitigation. Therefore, the signin and sendToken (along with its internal defaultNormalizer) functions are the vulnerable functions that would appear in a runtime profile during an exploit attempt.
Vulnerable functions
signinpackages/next-auth/src/core/routes/signin.ts
sendTokenpackages/core/src/lib/actions/signin/send-token.ts
defaultNormalizerpackages/core/src/lib/actions/signin/send-token.ts