CVE-2022-31093: Improper Handling of `callbackUrl` parameter in next-auth
Summary
CVE-2022-31093: Improper Handling of callbackUrl parameter in next-auth. Affects next-auth across 2 version ranges.
< 3.29.5
>= 4.0.0, < 4.5.0
Fixed in 3.29.5 or 4.5.0, depending on the release line you run. How to fix ↓
Check if this vulnerability affects your application
Upload a manifest or SBOM and we'll show whether you're affected, plus every other risky package in the same scan.
No signup required · Results in about 60 seconds
Background
The next-auth package is an authentication library for Next.js applications. It provides a simple and flexible way to implement authentication and authorization features. The package is widely used in the Next.js ecosystem and is known for its ease of use and robustness. However, a vulnerability has been discovered in versions before 3.29.5 (for v3 users) and before 4.5.0 (for v4 users) that allows an attacker to exploit the callbackUrl parameter, leading to API route handler timeouts and login failures.
Vulnerability Detail
The vulnerability arises from improper handling of the callbackUrl parameter in NextAuth.js. When an attacker sends a request with an invalid callbackUrl query parameter, the URL instantiation fails due to a malformed URL being passed into the constructor. This triggers an unhandled error, causing the API route handler to timeout and login to fail. The impact of this vulnerability can disrupt the authentication flow and potentially lead to unauthorized access or denial of service. The vulnerability has been assigned a CVSS score of 7.5, indicating a high severity level.
How To Fix
Latest published version: 4.24.15 as of 23 Oct 2026
npm install next-auth@4.24.15
Upgrading to it may include breaking changes; the versions below are the minimum fixed release for this vulnerability.
If you can't move to the latest
The minimum fixed version depends on the release line you run.
-
< 3.29.53.29.5npm install next-auth@3.29.5 -
>= 4.0.0, < 4.5.04.5.0npm install next-auth@4.5.0
Tip — Not sure which release line you're on? Vulert can find the fix for the version you are using. Scan free →
Workaround
If upgrading the next-auth package is not possible, a workaround can be implemented using advanced initialization. The code snippet below demonstrates the workaround:
import NextAuth from "next-auth"
function isValidHttpUrl(url) {
try {
return /^https?:///.test(url);
} catch {
return false;
}
}
export default async function handler(req, res) {
if (req.query.callbackUrl && !isValidHttpUrl(req.query.callbackUrl)) {
return res.status(500).send('');
}
return await NextAuth(req, res, /* your config */)
}
This workaround checks if the callbackUrl query parameter is present and if it is a valid HTTP or HTTPS URL. If the callbackUrl is invalid, it returns a 500 status code, effectively preventing the vulnerability from being exploited.
Conclusion
The next-auth package is vulnerable to an improper handling of the callbackUrl parameter, which can lead to API route handler timeouts and login failures. To mitigate this vulnerability, it is recommended to update to the latest patched version of the package. If upgrading is not possible, a workaround using advanced initialization is available. For further support on vulnerability remediation, please contact DevNack.com.
See every vulnerability recorded for next-auth →
FAQ
The vulnerability can cause API route handler timeouts and login failures, disrupting the authentication flow and potentially leading to unauthorized access or denial of service.
Versions before 3.29.5 for v3 users and before 4.5.0 for v4 users are affected.
To fix this vulnerability, update the next-auth package to the latest patched version. For v3 users, upgrade to version 3.29.5 or later. For v4 users, upgrade to version 4.5.0 or later.
Yes, a workaround is available using advanced initialization. Please refer to the provided code snippet in the 'Workaround' section for implementation details.
The CVSS score of this vulnerability is 7.5, indicating a high severity level.
References
Related vulnerabilities
Recent vulnerabilities recorded for next-auth.