CVE-2025–29927: Next.js Middleware Bypass Zafiyeti
Next.js middleware trusted a client-supplied x-middleware-subrequest header to decide that a middleware had already run, so an attacker could skip authentication checks and reach protected pages such as /admin. The author demonstrates this on a self-hosted vulnerable version and notes that newer releases require a deeper header value.
medium.com
Published on medium.com
Herkese selamlar. Normalde bu konuyu zafiyet ilk çıktığında değerlendirmeliydim ama hayat işte, bir şeyler engel oldu durdu.
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
Root cause
Likely the server did not verify that the x-middleware-subrequest header was set internally rather than by the client, so a client could claim a middleware had already executed and have it skipped.
Impact
An attacker could bypass middleware-based authentication and reach protected pages such as an admin panel, though the author notes that API calls behind that page may still require a token and return errors without one.
What the attacker needed
A vulnerable Next.js version; middleware used for authentication; ability to send custom HTTP headers
The fix
Upgrade Next.js to a patched release (14.2.25 or later for 14.x, 15.2.3 or later for 15.x), or block external requests carrying the x-middleware-subrequest header at a WAF or reverse proxy.
How it was found
- Set up a vulnerable Next.js version with a middleware that redirects unauthenticated requests for /admin to /login.
- Confirm that a normal request to /admin returns a 307 redirect to /login.
- Send a request to /admin with an x-middleware-subrequest header naming the middleware.
- On newer versions, repeat the middleware name in the header at least five times to meet the recursion depth check.
- Observe that the middleware is skipped and the admin page is returned.
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 websites, and its middleware is a checkpoint that runs before a page is shown, often to check whether someone is logged in. The bug is that the server believed a header sent by the visitor saying 'this checkpoint already ran', so it skipped the login check. A visitor could then open pages meant only for administrators.
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.