
Critical vulnerability in next.js : Bypass middleware authentication
This repository is provided strictly for educational purposes only. I did not discover this vulnerability - this is a demonstration and explanation of a publicly disclosed security issue. Using this knowledge to exploit vulnerable systems without authorization is illegal and unethical.
If you're using Next.js for your production apps, stop what you're doing and check your version number. There's a serious middleware vulnerability that could leave your entire authentication system wide open.
This critical vulnerability has been responsibly disclosed and patched, so I'm sharing this educational demonstration to help developers understand the issue and protect their systems.
The issue lies in how Next.js handles the internal x-middleware-subrequest HTTP header. This header was designed to prevent middleware recursion, but attackers can manipulate it to completely bypass middleware execution.
Think about what that means - any middleware-based security is potentially ineffective:
There have been reports of this vulnerability being used in the wild to access admin panels, user data, and even financial information. Some organizations had their sensitive data exposed without even knowing it.
This repo includes:
# Strips the problematic header
proxy_set_header x-middleware-subrequest "";
# Does the same thing for Apache users
RequestHeader unset x-middleware-subrequest
// Quick middleware fix until you can properly update
app.use((req, res, next) => {
delete req.headers['x-middleware-subrequest'];
next();
});
This vulnerability reinforces important security principles:
Check out these resources to build more secure Next.js apps:
This repository provides a technical explanation and demonstration of CVE-2025-29927 for educational purposes only. All information is based on publicly disclosed details that have been properly patched. If you discover security vulnerabilities in any software, always follow responsible disclosure practices:
This vulnerability demonstrates how even well-designed frameworks can have critical security flaws. Stay vigilant out there, and make updating dependencies part of your regular workflow.
Feel free to reach out with questions or if you need help implementing any of these fixes!