Bypassing Next.js Auth with CVE-2025–29927
Next.js middleware could be bypassed by sending a crafted x-middleware-subrequest header, causing the framework to skip authentication checks. An attacker could then reach protected pages, such as an internal diagnostics page, without logging in.
medium.com
Published on medium.com
In this walkthrough you’ll exploit CVE-2025–29927, a middleware bypass in Next.js that lets you skip authentication with one HTTP header. You’ll use it to reach a protected internal diagnostics page and pull its flag.
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 framework trusted an attacker-controlled header as an internal signal to skip middleware, and the protected page had no independent authentication check.
Impact
An attacker could bypass authentication and access protected pages, such as internal diagnostics, without valid credentials.
What the attacker needed
Next.js version before 15.2.3; Network access to the target
The fix
Upgrade Next.js to version 15.2.3 or later, and additionally verify authentication inside each protected route and strip the x-middleware-subrequest header at the edge.
How it was found
- Fingerprint the framework by checking response headers for X-Powered-By: Next.js.
- Identify the known CVE for Next.js middleware bypass via the x-middleware-subrequest header.
- Construct the header value with the middleware module name repeated five times, colon-separated.
- Send a request to the protected page with that header to bypass middleware and receive the page content.
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.
A website often uses a gatekeeper (middleware) to check if you are logged in before letting you see certain pages. This bug let anyone trick the gatekeeper into stepping aside by adding a special header to their request, so they could see private pages without logging in.
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.