← All articles Threat Detection

CVE-2025-29927: Next.js Middleware Auth Bypass Exploited in the Wild

By Ammar Khan, CEH · October 16, 2026 · CybernytronX Research
CVE-2025-29927: Next.js Middleware Auth Bypass Exploited in the Wild

On March 21, 2025, Vercel disclosed CVE-2025-29927, a critical authorization bypass in Next.js middleware affecting versions before 12.3.5, 13.5.9, 14.2.25, and 15.2.3. The flaw allows attackers to skip middleware logic by sending a crafted x-middleware-subrequest header, effectively bypassing authentication and authorization checks. Within days, public proof-of-concept exploits appeared, and by late March, reports of active exploitation in the wild emerged. This article provides a technical deep dive into the vulnerability, affected versions, attacker TTPs, detection rules, and mitigation strategies for security teams.

Background: What Is CVE-2025-29927?

CVE-2025-29927 is a critical authorization bypass vulnerability in Next.js, a popular React framework used for server-side rendering and API routes. The flaw resides in how Next.js handles the x-middleware-subrequest header, which is used internally to prevent infinite loops when middleware makes subrequests. An attacker can craft a request with this header set to a specific value, causing the middleware to be skipped entirely. This bypasses any authentication, authorization, or security checks implemented in middleware.

According to the GitHub Security Advisory, the vulnerability has a CVSS v3.1 score of 9.1 (Critical). The flaw affects all Next.js applications that rely on middleware for security controls, including those using NextAuth.js, custom JWT validation, or role-based access control.

“The vulnerability allows an attacker to bypass middleware-based authorization checks by sending a specially crafted header,” the advisory states. “This can lead to unauthorized access to protected routes and data.”

Affected Versions and Vendor Advisory

Vercel patched CVE-2025-29927 in the following versions:

All earlier versions are vulnerable. The advisory recommends upgrading immediately. For applications that cannot upgrade, Vercel provided a workaround: block external user access to the x-middleware-subrequest header at the edge or reverse proxy level. Detailed guidance is available in the Vercel blog post and the NVD entry.

Attacker TTPs and MITRE ATT&CK Mapping

Exploitation is straightforward. An attacker sends an HTTP request to a protected endpoint with the header x-middleware-subrequest: middleware (or a similar value that matches the internal subrequest pattern). The middleware is skipped, and the request proceeds to the route handler without authentication. This technique aligns with MITRE ATT&CK T1190 (Exploit Public-Facing Application) and T1078 (Valid Accounts) if the attacker gains access to privileged functionality.

In observed attacks, adversaries have used the bypass to access admin panels, API endpoints, and sensitive data. Some campaigns have chained the bypass with other vulnerabilities to achieve remote code execution. For example, if an application exposes an admin API that allows file uploads or command execution, the bypass can lead to full compromise.

Detection: Sigma, YARA, and Network Rules

Sigma Rule for Web Server Logs

The following Sigma rule detects requests containing the x-middleware-subrequest header in web server logs (e.g., Apache, Nginx, or cloud WAF logs). It is designed to be converted to your SIEM's query language.

title: Next.js Middleware Bypass Attempt (CVE-2025-29927)
id: 5a4b3c2d-1e2f-3a4b-5c6d-7e8f9a0b1c2d
status: experimental
description: Detects HTTP requests with the x-middleware-subrequest header, indicating an attempt to exploit CVE-2025-29927.
references:
  - https://github.com/vercel/next.js/security/advisories/GHSA-f82v-jwr5-mffw
author: CybernytronX
date: 2025/04/10
logsource:
  category: webserver
detection:
  selection:
    cs-method: 'GET'
    cs-uri-query|contains: 'x-middleware-subrequest'
  condition: selection
falsepositives:
  - Legitimate internal subrequests from Next.js middleware (rare in external logs)
level: high

Note: In many web servers, custom headers are not logged by default. Ensure your logging configuration captures all request headers, or use a WAF that inspects headers.

YARA Rule for Memory or Traffic Analysis

This YARA rule can be used to scan network traffic captures (PCAP) or memory dumps for the malicious header string.

rule CVE_2025_29927_Header
{
    meta:
        description = "Detects x-middleware-subrequest header used in CVE-2025-29927 exploitation"
        author = "CybernytronX"
        date = "2025-04-10"
        reference = "https://github.com/vercel/next.js/security/advisories/GHSA-f82v-jwr5-mffw"
    strings:
        $header = "x-middleware-subrequest" nocase ascii wide
    condition:
        $header
}

Suricata Rule for Network Detection

This Suricata rule alerts on HTTP requests containing the x-middleware-subrequest header.

alert http any any -> any any (msg:"CVE-2025-29927 Next.js Middleware Bypass Attempt"; flow:to_server,established; content:"x-middleware-subrequest"; http_header; nocase; classtype:attempted-admin; sid:1000001; rev:1;)

Deploy this rule on your network IDS/IPS or cloud WAF. Tune to reduce false positives from internal health checks.

Mitigation and Patching

The primary mitigation is to upgrade to a patched version of Next.js. If immediate upgrading is not possible, implement the following compensating controls:

Vercel's advisory also recommends rotating any secrets or tokens that may have been exposed if you suspect exploitation.

Why This Matters for Defenders

CVE-2025-29927 is a stark reminder that middleware is not a security boundary. Many development teams treat Next.js middleware as a convenient place to enforce authentication and authorization, but as this vulnerability demonstrates, a single header can bypass all those checks. Defenders must adopt a defense-in-depth approach: validate permissions at every layer, log and monitor all request headers, and maintain an inventory of frameworks and their versions. Given the widespread adoption of Next.js in enterprise environments, this flaw has a large attack surface. Security teams should prioritize patching and assume that any middleware-protected route may have been accessed without authorization.

Sources

Frequently Asked Questions

What is CVE-2025-29927?

CVE-2025-29927 is a critical authorization bypass vulnerability in Next.js middleware. Attackers can skip middleware by sending a crafted x-middleware-subrequest header, bypassing authentication and authorization checks.

Which versions of Next.js are affected?

All versions before 12.3.5, 13.5.9, 14.2.25, and 15.2.3 are vulnerable. Upgrade to the latest patched version immediately.

Is CVE-2025-29927 being exploited in the wild?

Yes. Public proof-of-concept exploits appeared shortly after disclosure, and multiple reports indicate active exploitation attempts. Organizations should assume they are targets.

How can I detect exploitation attempts?

Monitor web server and WAF logs for the x-middleware-subrequest header. Use the Sigma, YARA, and Suricata rules provided in this article.

What if I cannot patch immediately?

Block the x-middleware-subrequest header at your reverse proxy or edge, and enforce authentication at the route handler level. See Vercel's advisory for detailed workarounds.

Does this affect applications using NextAuth.js?

Yes, if NextAuth.js is configured to use middleware for session validation. The bypass skips middleware entirely, so any authentication logic in middleware is ineffective.

Need expert help with this?

CybernytronX specializes in vulnerability assessment, penetration testing, and SOC build-out. Our team can help you identify exposed Next.js instances, validate patches, and implement robust detection. We also offer Ethereon AI, our AI-powered threat detection platform, to continuously monitor for exploitation attempts. Contact us at cybernytronx.com/contact.html or learn more about Ethereon at cybernytronx.com/ethereon.html.

AK

Ammar Khan — Founder, CybernytronX

Certified Ethical Hacker (CEH), B.S. Cybersecurity, Google Certified. 5+ years pentesting, creator of Ethereon AI threat detection. Has remediated 50+ environments and recovered 20+ compromised domains. Hire CybernytronX →

← Back to all articles