On March 21st, 2025, Next.js disclosed a 9.1 critical vulnerability (CVE) that would allow attackers to bypass middleware-based authorization checks. This issue was originally discovered and investigated by Rachid Allam (zhero) who authored a detailed research paper to outline the specifics.

What is Next.js Middleware

Next.js middleware is a feature that runs code before request completion, allowing developers to modify responses by rewriting, redirecting, changing headers, or responding directly. Next.js middleware is a powerful tool that enables teams to do a lot but the main use cases are:

  • Path rewriting: Dynamically change requested paths
  • Server-side redirects: Easily reroute users based on specific conditions
  • Included response headers: Headers that could be introduce are Content Security Policy (CSP)
  • Authentication and authorization checks: Confirming user identity and checking session cookies before access to specific pages or API routes are granted

Common pattern: Protecting routes by intercepting requests to check session cookies and permissions before granting access (e.g., for /dashboard/admin), forwarding valid requests or redirecting unauthorized users to login.

What is CVE-2025-29927

The CVE-2025-29927 vulnerability comes from a design flaw in how Next.js handles the x-middleware-subrequest header, which was originally meant to mitigate infinite middleware execution loops internally. The vulnerability lies in the fact that this header check can be exploited. By simply adding the x-middleware-subrequest header with the correct value to a request, an attacker can successfully bypass any middleware-based protection mechanisms.

Which Versions Are Affected

Next.js versions affected:

  • 11.1.4 <= 13.5.6
  • 14.0 < 14.2.25
  • 15.0 < 15.2.3
Applications Hosted on Vercel and Netlify Are Not Impacted

Applications deployed as static exports (where middleware doesn’t execute) are not impacted.

Remediation Actions Teams Should Take

The company behind Next.js, quickly released patches for the vulnerability.

Official Patches:

  • For Next.js 15.x, this issue is fixed in 15.2.3
  • For Next.js 14.x, this issue is fixed in 14.2.25
  • For Next.js 13.x, this issue is fixed in 13.5.9
  • For Next.js 12.x, this issue is fixed in 12.3.5

If patching is infeasible, it is recommended to implement a workaround.

Suggested Workarounds:

A workaround if upgrading to a safe version is infeasible, filtering the x-middleware-subrequest header from requests before they reach the application (case insensitive) is recommended.

Additionally, Cloudflare has released a managed WAF rule, but it's opt-in only because some third-party authentication vendors were failing requests where they use the x-middleware-subrequest header

Miggo Ensures Teams Can Detect and Respond to Next.js Exploits

CVE-2025-29927 is a critical reminder of how implementing details in web frameworks can introduce unintended security vulnerabilities. Miggo was designed to detect and respond to vulnerabilities just like this one. How would Miggo users be equipped to act when an exploit like CVE-2025-29927 is exposed?

  1. Users would start by using an up-to-date and real-time application ecosystem graph to understand how new CVEs potentially impact compromised services.
  2. Then, they would be provided with an accurate risk score built with key factors like: runtime application context (internet facing, sensitive data access, etc.) and function level reachability of the CVE.
  3. Once the noise has been reduced and the finding validated, developers can quickly deploy a patch, with the response guidance provided by Miggo.
Screenshot of Miggo's Vulnerabilties View
Miggo's Vulnerabilties View

Want to learn more about how Miggo can provide you with what’s required to detect and respond to application level exploits? Book time with an expert.

<script src="https://cdn.jsdelivr.net/npm/gsap@3.12.5/dist/gsap.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/gsap@3.12.5/dist/Flip.min.js"></script>

<script>
  document.addEventListener("DOMContentLoaded", (event) => {
    gsap.registerPlugin(Flip);
    const state = Flip.getState("");
    const element = document.querySelector("");
    element.classList.toggle("");
    Flip.from(state, {
      duration: 0,
      ease: "none",
      absolute: true,
    });
  });
</script>
<script src="https://cdn.jsdelivr.net/npm/gsap@3.12.5/dist/gsap.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/gsap@3.12.5/dist/Flip.min.js"></script>

<script>
  document.addEventListener("DOMContentLoaded", (event) => {
    gsap.registerPlugin(Flip);
    const state = Flip.getState("");
    const element = document.querySelector("");
    element.classList.toggle("");
    Flip.from(state, {
      duration: 0,
      ease: "none",
      absolute: true,
    });
  });
</script>
Key takeaways

On March 21st, 2025, Next.js disclosed CVE-2025-29927, a critical vulnerability allowing attackers to bypass middleware authorization checks by exploiting the x-middleware-subrequest header. This header, designed to prevent infinite middleware loops, became an exploitation vector when added to requests. Patches are available for affected versions 11.1.4 through 15.2.2. Miggo detects these vulnerabilities through real-time application graphs, provides accurate risk scoring using runtime context and function-level reachability, then delivers response guidance for rapid patching.

Frequently Asked Questions

What is CVE-2025-29927 and why is it critical?

CVE-2025-29927 is a 9.1 critical vulnerability in Next.js that allows attackers to bypass middleware-based authorization checks. The flaw stems from how Next.js handles the x-middleware-subrequest header, originally designed to prevent infinite middleware loops. Attackers add this header with the correct value to bypass protection mechanisms that guard routes like admin dashboards.

Which Next.js versions are affected by this vulnerability?

Affected versions include Next.js 11.1.4 through 13.5.6, 14.0 through 14.2.24, and 15.0 through 15.2.2. Applications hosted on Vercel and Netlify are not impacted. Applications deployed as static exports are also not impacted because middleware does not execute in that configuration.

How do we patch this vulnerability?

Upgrade to Next.js version 15.2.3 for 15.x, 14.2.25 for 14.x, 13.5.9 for 13.x, or 12.3.5 for 12.x. If upgrading is infeasible, filter the x-middleware-subrequest header from requests before they reach the application. Cloudflare released an opt-in managed WAF rule as an additional workaround option.

What is Next.js middleware typically used for in our applications?

Next.js middleware runs code before request completion to modify responses. Main use cases include path rewriting, server-side redirects, adding response headers like Content Security Policy, and authentication and authorization checks. The common pattern involves protecting routes by checking session cookies and permissions before granting access to pages or API routes.

How does Miggo help detect and respond to vulnerabilities like this?

Miggo provides a real-time application ecosystem graph to understand how new CVEs impact services. It delivers accurate risk scores using runtime application context like internet exposure and function level reachability of the CVE. After validation, Miggo provides response guidance so developers can quickly deploy patches.