December 4, 2026
Next.js Middleware Bypass: One Header Skipped Auth
CVE-2025โ29927 let a single request header convince Next.js that its own middleware had already run, so login checks never happened

By Muhammad Asim Shahzad
2 min read
CVE-2025โ29927 let a single request header convince Next.js that its own middleware had already run, so login checks never happened
AI-assisted: drafted with AI help from public sources, then reviewed and edited. This is an analytical case study of a public disclosure, not my own discovery.
One request header was enough to switch off authentication on self-hosted Next.js apps that guarded routes in middleware. This Next.js middleware bypass, CVE-2025โ29927, was rated CVSS 9.1 (Critical) and reached back through years of releases. For a framework pulling roughly 9.4 million weekly downloads at the time, that is a lot of admin panels.
Disclaimer:_ Educational and defensive use only. Fixed in Next.js 12.3.5, 13.5.9, 14.2.25 and 15.2.3, with the advisory published 21 March 2025. Header values and request samples are intentionally omitted._
Vulnerability Overview
- Type: Authorization bypass via a client-controllable internal header
- CWE: CWE-285 (Improper Authorization) and CWE-863 (Incorrect Authorization), as listed in the GitHub advisory
- CVE / CVSS: CVE-2025โ29927; CVSS 3.1 9.1 (Critical), per GHSA-f82v-jwr5-mffw
- Bounty: Not reported
How the Next.js Middleware Bypass Worked (high level)
Next.js middleware runs before a request reaches its page or API route. Teams use it for redirects and headers, and very often for "is this user logged in?" checks.
Middleware can trigger its own internal subrequests, and something has to stop that from looping forever. Next.js did it with an internal header, x-middleware-subrequest, which records which middleware a request had already passed through. If the header said the current middleware had run, or in newer versions had run enough times to hit the recursion limit, Next.js skipped it and forwarded the request untouched.
The flaw is that nothing stopped an outside client from sending that header. Its expected contents were not secret either: they were derived from the middleware file's path, which follows framework conventions. Rachid Allam (zhero) and Yasser Allam (inzo_) found the logic in an old release first, then realized that every version since 11.1.4 shared it in some form.
With middleware skipped, the researchers showed protected routes opening up, a content security policy disappearing and, where a CDN cached the result, a cache-poisoning denial of service. Apps hosted on Vercel and Netlify were reported as not vulnerable at the time of the advisory.
Business Impact
Any self-hosted app whose only access control lived in middleware was effectively public. Middleware was the documented place for auth checks, so this was standard practice, not a rare misconfiguration. Triage was slow: the report went in on 27 February 2025, Vercel confirmed it on 17 March and the fix shipped on 18 March.
Preventing Next.js Middleware Bypass-Style Bugs (my own analysis)
1. Strip internal headers at the edge. Upgrade first. Until then, have your proxy drop or reject x-middleware-subrequest from outside requests, as the advisory recommends.
2. Make internal signals unforgeable. A loop marker should carry a per-deployment HMAC that clients cannot compute.
3. Authorize next to the data. Middleware is a convenient first gate. The route handler or data layer must check the session again.
# Pseudocode: edge filtering, signed internal markers, authorization at the handler
INTERNAL_PREFIXES = ("x-middleware-", "x-internal-")
def edge_proxy(req):
for name in list(req.headers):
if name.lower().startswith(INTERNAL_PREFIXES):
del req.headers[name] # clients never set internal state
return forward(req)
def is_internal_hop(req):
tag = req.headers.get("x-internal-hop", "")
want = hmac_sha256(DEPLOY_SECRET, req.request_id) # secret never leaves the server
return constant_time_equal(tag, want)
def admin_report_handler(req):
s = sessions.verify(req.cookies.get("sid"))
if not s or "admin" not in s.roles:
return deny(403) # re-checked even if middleware passed
return reports.load()
# Test: spoofed internal header -> stripped; no session -> 403 even with middleware skipped# Pseudocode: edge filtering, signed internal markers, authorization at the handler
INTERNAL_PREFIXES = ("x-middleware-", "x-internal-")
def edge_proxy(req):
for name in list(req.headers):
if name.lower().startswith(INTERNAL_PREFIXES):
del req.headers[name] # clients never set internal state
return forward(req)
def is_internal_hop(req):
tag = req.headers.get("x-internal-hop", "")
want = hmac_sha256(DEPLOY_SECRET, req.request_id) # secret never leaves the server
return constant_time_equal(tag, want)
def admin_report_handler(req):
s = sessions.verify(req.cookies.get("sid"))
if not s or "admin" not in s.roles:
return deny(403) # re-checked even if middleware passed
return reports.load()
# Test: spoofed internal header -> stripped; no session -> 403 even with middleware skippedKey Takeaways
- A header that changes security behavior has to be either unforgeable or impossible for clients to send.
- Middleware is a filter, not an authorization layer. Put a check next to the data.
- Hosting matters: a platform's edge can quietly protect you, until you self-host.
Credit & Sources
Discovered by Rachid Allam (zhero) and Yasser Allam (inzo_). Primary sources: Next.js and the corrupt middleware: the authorizing artifact, March 2025, and the GitHub advisory GHSA-f82v-jwr5-mffw. Facts come from those pages; analysis and code are original.
Next breakdown: the Okta login bug where a long username meant the password was never checked. Follow @masimshahzad for daily bug bounty breakdowns.