Skip to content
Access control Write-up Beginner

CVE-2025–29927: The Shocking Next.js

Next.js middleware, which is often used for authorization and security headers, could be skipped entirely when a request carried a crafted x-middleware-subrequest header. An attacker could therefore reach protected routes without authentication and bypass protections such as CSP.

medium.com

Published on medium.com

CVE-2025–29927 was discovered by security researchers Rachid Allam and Yasser Allam and was publicly disclosed on March 21, 2025. This latest CVE in Next.js marks Middleware as new point for exploitation for attackers.

Wrench, 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

The framework trusted a client-supplied header to decide whether middleware had already run, so a request could claim to be an internal sub-request and skip all middleware logic.

Impact

Attackers could bypass authorization to reach restricted areas, and could also circumvent CSP and cache-control headers set by middleware, though Vercel-hosted deployments were automatically protected.

What the attacker needed

Self-hosted Next.js in an affected version; middleware used for access control or headers; ability to send a custom HTTP header

The fix

It was fixed in Next.js 15.2.3 and 14.2.25; otherwise the header should be stripped at a load balancer, reverse proxy or custom server.

How it was found

  1. Identify a Next.js application that relies on middleware for access control.
  2. Send a request to a protected route with an x-middleware-subrequest header whose value matches the middleware name for that version.
  3. Observe that middleware is skipped and the protected resource is returned without authorization.

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.

Middleware is code that runs before a page is served, often to check whether you are logged in. Next.js used a special request header to stop middleware from running again inside itself, but it trusted that header from anyone. By sending that header, an attacker made the login check disappear and reached pages meant only for authorised 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.