Next.js middleware bypass (CVE-2025-29927): am I affected and how to fix it
Short answer
CVE-2025-29927 lets a request with a crafted x-middleware-subrequest header skip Next.js middleware entirely, so any login or role check done only in middleware does not run. Upgrade to a fixed release (12.3.5, 13.5.9, 14.2.25 or 15.2.3 or later) and also check authorisation inside your route handlers and data layer. Apps hosted on Vercel or Netlify were described as not affected by the vendor, but self-hosted ones were.
Why you got this
Next.js middleware runs before a request reaches a page or API route, so many projects put authentication and admin checks there. Internally, Next.js uses the x-middleware-subrequest header to avoid middleware loops. In the affected versions, an outside caller could send that header with the right value and the framework would skip the middleware.
The result is that routes you believed were protected, such as /admin or /dashboard, could be fetched without logging in. The issue was disclosed in March 2025 and is rated critical. It matters most for self-hosted apps running next start or the standalone output behind a plain reverse proxy.
What to do now
Check your version with npm ls next. Affected versions run from 11.1.4 up to (but not including) 12.3.5, 13.5.9, 14.2.25 or 15.2.3, depending on your major version.
Upgrade to the latest patch of your major version, rebuild and redeploy. If you cannot upgrade today, block the header at your proxy as a stop-gap.
Review your access logs for requests that carry x-middleware-subrequest, which no legitimate visitor sends, and for unexpected access to protected routes.
If sensitive pages or data were reachable, rotate session secrets and consider what you must disclose.
How to fix it properly
Upgrade to a patched release of your line. Pick the one that matches your major version.
npm install next@latest
# or stay on your major: [email protected], [email protected], [email protected], [email protected] (or newer)Temporary protection in nginx: strip the header from external requests before they reach the app.
location / {
proxy_set_header x-middleware-subrequest "";
proxy_pass http://127.0.0.1:3000;
}The lasting fix is defence in depth. Do not let middleware be the only gate: verify the session inside every route handler, server action and data access function.
// app/api/admin/users/route.ts
import { getSession } from '@/lib/auth';
export async function GET() {
const session = await getSession();
if (!session || session.role !== 'admin') {
return new Response('Unauthorized', { status: 401 });
}
// ...load data
}Use middleware for convenience, such as redirecting a visitor to the login page, but treat it as a UX layer, not the security boundary.
How to check it is fixed
After upgrading, confirm the installed version again with npm ls next and in the build output. Then test a protected route without a session: it should return 401, 403 or a redirect, with and without the header.
The deep ScanAnt scan, available only on sites you have proved you own and only when you tick the deep option, detects the Next.js version, compares it with known vulnerabilities and tests this bypass with a single harmless GET that carries the crafted header. It records only whether a protected page answered. It does not replace checking authorisation in your own handlers.
Questions
Am I affected if I use Vercel?
The Next.js maintainers said apps hosted on Vercel and Netlify were not affected, and static exports are not either. Self-hosted next start and standalone deployments were. Upgrade anyway.
Is it still a problem after patching?
The specific bug is fixed, but any design that relies on middleware alone is fragile. Check auth in handlers too.
How do I know if someone used it?
Search access logs for requests containing x-middleware-subrequest. Many proxies do not log request headers by default, so you may have no record.
Does it affect auth libraries like NextAuth?
If they enforce access in middleware, then yes, for unpatched versions. Check the library advisory and patch Next.js.
Related checks
Check your site after the fix
The quick scan is free for any public site and needs no signup. Checks that touch your database or files run only after you prove you own the site.
Choose a scan level →