Skip to content
Access control Write-up Beginner

Next.js Middleware Vulnerability: How CVE-2025–29927 Enables Authorization Bypass

Next.js middleware, often used for authentication and authorization, could be bypassed by sending a crafted x-middleware-subrequest header. An attacker could then reach protected routes such as admin dashboards without logging in.

nitinsgavane Follow

Published on medium.com

Hey there! In today’s blog, I’m diving into the Next.js Middleware Exploit — specifically CVE-2025–29927, an authorization bypass vulnerability.

Nitin Gavhane, on medium.com

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 application trusted a client-supplied header that was meant only for internal use to track middleware recursion depth, so an attacker could make the middleware think it had already run too many times and skip it.

Impact

An attacker could bypass authorization checks and access protected content or functionality, potentially exposing sensitive data or admin features.

What the attacker needed

Target uses vulnerable Next.js middleware; attacker can send HTTP requests; protected route exists

The fix

The vulnerability was fixed in Next.js; users should upgrade to a patched version and, as a workaround, block external requests containing the x-middleware-subrequest header.

How it was found

  1. Find a protected route that requires authentication, such as /admin.
  2. Send a normal request to the protected route and observe access denied or a redirect.
  3. Send the same request with the x-middleware-subrequest header set to a bypass value.
  4. Check if the response is 200 OK with protected content instead of access denied.
  5. If needed, try other header values for older versions or projects with a src directory.
  6. Compare responses with and without the header to confirm the vulnerability.

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. Middleware is code that runs before a page loads, often to check if you are logged in. This bug let anyone add a special header to a web request so the login check was skipped, and they could see pages meant only for logged-in users.

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.

Similar reports

View all

Same bug class and techniques, clearest first.

Broken access control

The lesson behind this report.

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.