A critical vulnerability in the Next.js framework, officially disclosed on March 21, 2025, allows attackers to bypass middleware security controls through a simple header manipulation. This post summarizes what we know about CVE-2025-29927, how you can mitigate the vulnerability, and how Invicti can help you detect and confirm your organization’s risk.
What you need to know
The vulnerability allows attackers to completely bypass the middleware functionality by including a specially crafted x-middleware-subrequest
header in their requests. Middleware can best be thought of as a processing chain that lets software modules inspect, modify, or reroute an HTTP request before it reaches its final code handler. It is a natural place to implement cross-cutting concerns like authentication—a very common pattern is having a middleware implement that logic that expresses “redirect to /login
if there is not a valid authentication cookie”.
This vulnerability is particularly concerning because Next.js middleware is commonly used for critical security functions such as authentication, authorization, path rewriting, and implementing security headers, all of which can be trivially bypassed by an attacker.
To get an idea of how bad this can be, imagine an airport security checkpoint where security agents (the middleware) carefully check everyone’s ID and boarding pass before letting them proceed to the gate. Now, suppose there’s a secret phrase that, when whispered to any security agent, causes them to immediately wave you through without checking anything. That’s essentially what the Next.js middleware authorization bypass vulnerability allows: using a special HTTP header to completely bypass security checks that would normally protect sensitive routes and resources.
If your answer to BOTH of the following questions is “yes”, your application is vulnerable unless patched:
next start
with output: 'standalone'
?Applications are particularly at risk if:
Applications hosted on Vercel or Netlify are not affected, as these platforms have implemented mitigations at their edge layers. Applications deployed as static exports (where middleware is not executed) are also not affected.
If you don’t know the details of your Next.js usage or want the ability to assess it independently, running an automated DAST tool to confirm your vulnerability is a great place to start.
Next.js middleware uses an internal header called x-middleware-subrequest
to prevent recursive requests from triggering infinite loops. The security vulnerability allows an attacker to manipulate this header to trick the Next.js application into skipping middleware execution entirely.
For different versions of Next.js, the exploit works slightly differently:
x-middleware-subrequest: pages/_middleware
x-middleware-subrequest: middleware:middleware:middleware:middleware:middleware
src/middleware:src/middleware:src/middleware:src/middleware:src/middleware
if using the src
directory)When this header is present with the appropriate value, the middleware is completely bypassed, allowing the request to reach its original destination without any security checks or modifications that would have been applied by the middleware.
The vulnerability is detected through passive monitoring of web traffic during a security scan without making active requests. Invicti Enterprise uses this technique with its vulnerability database to detect the flaw. This technique looks for the x-powered-by: Next.js
header in responses, which confirms the application is using Next.js. The presence of the vulnerable version is further confirmed by evaluating the next.version
function in the browser’s JavaScript context to extract the precise version
We then compare this value to our continuously updated database of known CVEs and network detection signatures to determine if an insecure version of Next.js has been encountered.
As of Tuesday, March 25, 2025, this check is live for all Invicti Enterprise, Invicti Standard, and Acunetix 360 customers.
Invicti’s security research team has developed a check for the Acunetix engine to detect if your applications are vulnerable to CVE-2025-29927. As of Monday, March 24, 2025, this check is live for all Acunetix Premium customers.
Here’s how the active check works step by step:
x-powered-by: Next.js
header in responses.middleware:middleware:middleware:middleware:middleware
(and the src
variant)pages/_middleware
middleware
Y-Middleware-Subrequest
, to confirm it still redirects (307).x-middleware-subrequest
header at your edge/proxy level (not in middleware itself).Invicti Security would like to acknowledge Rachid Allam and Yasser Allam for their original research and writeup of their findings, as well as our internal teams that worked to turn out a check to customers within a single business day.
Our security team is continuously monitoring this situation and will update as more information becomes available.
There is an urban legend that used to circulate around schoolyards about summoning ghosts by chanting their names repeatedly in the dark in front of a mirror. Apparently, the name was wrong—instead of Bloody Mary, those kids just had to say “Middleware-y” five times in an HTTP header to summon a far scarier security bypass…