A newly uncovered critical vulnerability in the popular Next.js React framework is raising alarms among developers and security professionals alike. Tracked as CVE-2025-29927, the flaw has been assigned a CVSS score of 9.1, indicating a critical risk level. The vulnerability enables threat actors to bypass middleware-based authorization checks by exploiting the internal x-middleware-subrequest
header—potentially granting unauthorized access to sensitive, privileged resources.
Discovered and publicly disclosed by security researcher Rachid Allam (also known by the handles zhero and cold-try), the flaw has already been addressed by the Next.js team in multiple patch releases. However, due to the availability of technical details online, systems that have not been updated remain at high risk of exploitation.
CVE-2025-29927 Overview
The vulnerability resides in the way Next.js manages internal subrequests using the x-middleware-subrequest
header. Originally designed to prevent infinite request loops in middleware pipelines, this header can be manipulated by an attacker in specific circumstances to entirely skip middleware execution.
In systems that rely solely on middleware for handling authorization and access control, this creates a critical security hole. Attackers can forge requests with the manipulated header to bypass authentication checks, allowing access to admin-only pages, sensitive data endpoints, or restricted user resources—without ever logging in.
Vulnerability Details
Attribute | Description |
---|---|
Threat Name | CVE-2025-29927 |
Threat Type | Authorization Bypass via Header Manipulation |
Detection Names | N/A (Application-level vulnerability; not malware-based) |
Symptoms of Exploitation | Unauthenticated access to admin or restricted routes in web apps |
Damage | Unauthorized data access, privilege escalation, potential data breaches |
Distribution Methods | Not distributed like malware; must be exploited through crafted HTTP requests |
Danger Level | Critical (CVSS 9.1) |
Affected Framework | Next.js |
Vulnerable Versions | Prior to: 12.3.5, 13.5.9, 14.2.25, 15.2.3 |
Associated Email | N/A |

Address CVE-2025-29927
With SpyHunter
Patched Versions Now Available
The Next.js team has responded swiftly, issuing patches for all actively maintained versions of the framework. The vulnerability has been resolved in the following versions:
- 12.3.5
- 13.5.9
- 14.2.25
- 15.2.3
Developers who are unable to immediately upgrade should block external requests containing the x-middleware-subrequest
header at the server level to mitigate the risk temporarily.
Real Risk to Middleware-Only Security Models
According to a report from JFrog, this vulnerability is particularly dangerous for applications that use middleware as the sole method for user authorization. Without additional authentication layers (such as server-side session validation or route guards), a malicious actor can easily bypass protection using a modified HTTP header.
This flaw highlights the importance of layered security models in web applications. Relying exclusively on middleware for access control introduces fragility and increases the attack surface when unexpected behaviors like this emerge.
Removal & Mitigation Guide for CVE-2025-29927
The CVE-2025-29927 vulnerability in the Next.js framework allows attackers to bypass middleware-based authorization by manipulating the x-middleware-subrequest
header. To protect your application, follow the steps below to remove the vulnerability and harden your security posture.
Step 1: Upgrade to a Patched Version
The safest and most effective way to address this flaw is by upgrading Next.js to a patched version.
Upgrade Targets:
- 12.3.5
- 13.5.9
- 14.2.25
- 15.2.3
How to upgrade:
Open your terminal and run the appropriate command for your project:
bashCopyEditnpm install next@12.3.5
# or for newer versions
npm install next@15.2.3
Then, rebuild your project:
bashCopyEditnpm run build
Step 2: Implement Temporary Header Filtering (If You Can’t Patch)
If you’re unable to upgrade immediately, implement a server-side filter to block requests containing the x-middleware-subrequest
header from untrusted sources.
Example (Next.js Custom Server – Express):
javascriptCopyEditconst express = require('express');
const next = require('next');
const app = next({ dev: false });
const handle = app.getRequestHandler();
app.prepare().then(() => {
const server = express();
// Header check middleware
server.use((req, res, next) => {
if (req.headers['x-middleware-subrequest']) {
return res.status(403).send('Forbidden: Malicious header detected');
}
next();
});
server.all('*', (req, res) => {
return handle(req, res);
});
server.listen(3000, () => {
console.log('Server listening on port 3000');
});
});
Example (Vercel Middleware – Edge Function Filter):
jsCopyEditimport { NextResponse } from 'next/server';
export function middleware(request) {
const headerValue = request.headers.get('x-middleware-subrequest');
if (headerValue) {
return new Response('Forbidden', { status: 403 });
}
return NextResponse.next();
}
Step 3: Strengthen Authorization Logic
Avoid relying solely on middleware for authentication or access control.
- Use server-side checks on API routes and page-level logic.
- Verify user sessions or tokens within your server logic (e.g., inside
getServerSideProps
or API route handlers). - Implement role-based access control (RBAC) at the route or controller level, not just middleware.
Step 4: Test for Exploitable Behavior
After patching or mitigating:
- Simulate a forged request with the
x-middleware-subrequest
header. - Attempt to access restricted routes or admin panels.
- Verify that the request is denied or redirected appropriately.
Use tools like Postman, curl, or Burp Suite to test request manipulation:
bashCopyEditcurl -H "x-middleware-subrequest: 1" https://yourdomain.com/admin
Step 5: Monitor and Log Suspicious Activity
- Set up WAF (Web Application Firewall) rules to detect suspicious headers.
- Use logging tools to monitor for repeated requests containing the
x-middleware-subrequest
header. - Investigate anomalies in access logs, especially for admin or restricted routes.
Conclusion
CVE-2025-29927 is a highly critical flaw in the Next.js framework that presents a real threat to web applications handling sensitive or privileged content. With public disclosure and technical details already available, time is of the essence. Developers must prioritize patching or apply server-side mitigations immediately to prevent unauthorized access through this vector.
Failure to address this vulnerability could result in unauthorized data access, privilege escalation, and potential compliance violations, especially in apps storing personal or financial information.

Address CVE-2025-29927
With SpyHunter