CVE-2025–29927 — Bypass de Middleware en Next.js
A vulnerability in Next.js allows attackers to bypass middleware-based authentication by manipulating the x-middleware-subrequest header. An attacker could access protected routes without authorisation.
Published on medium.com
En los últimos días, la comunidad de seguridad ha estado en alerta por el CVE-2025–29927, una vulnerabilidad crítica en Next.js que permite a atacantes evadir los mecanismos de autenticación implementados en la capa de middleware. Este fallo ha generado bastante desinformación, con PoC’s iniciales que sugerían que el…
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Impact
An attacker could bypass authentication and access protected routes, potentially exposing sensitive data and APIs, and may also evade security policies such as CSP and cache poisoning.
What the attacker needed
Target runs vulnerable Next.js version; Middleware used for authentication; Attacker can send custom headers
The fix
The vulnerability was fixed in Next.js versions 12.3.5, 13.5.9, 14.2.25, and 15.2.3; additionally, blocking the x-middleware-subrequest header at intermediate servers and implementing authentication in the backend are recommended.
How it was found
- Search for Next.js applications using Shodan with the query 'Next JS "X-Middleware-Rewrite" 307'.
- Identify a target running a vulnerable Next.js version (e.g., 13.4.19).
- Send a request to a protected route (e.g., /dashboard) and observe the x-middleware-rewrite header in the response.
- Add the header X-Nextjs-Data: 1 to the request and check for a 307 response with x-nextjs-rewrite header.
- Add the polyglot X-Middleware-Subrequest header to the request.
- Observe that the dashboard is rendered without authentication.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
Next.js is a framework for building web applications. Middleware is code that runs before a page is shown, often used to check if a user is logged in. This bug lets an attacker send a special header that tricks Next.js into skipping the middleware, so they can see pages that should require login.
What is Access control?
A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.