CVE-2025-29927: The Next.js Middleware Bypass Explained

The vulnerability skips Next.js middleware security checks by adding a single HTTP header

Next.js middleware normally checks if users can access protected pages. It runs before your page loads and can block unauthorized visitors.

But malicious users can add a special header called x-middleware-subrequest to their HTTP requests. When they do this, Next.js skips running your middleware completely. This means all your security checks get bypassed.

Update: the patched versions below are not safe versions anymore

The versions in the table below still fix CVE-2025-29927, but its “No action needed” rows no longer hold. In December 2025, Next.js disclosed CVE-2025-66478, a CVSS 10.0 remote code execution bug in App Router apps on Next.js 15.x and 16.x, and it has shipped more security releases since.

Upgrade to the latest patch release of your Next.js line and check the Next.js security updates page.

Next.js 16 also renamed middleware.ts to proxy.ts, as the Next.js 16 release post explains.

Here’s what a normal request looks like:

And here’s what a malicious request looks like:

That’s it. By adding this one header, they bypass all your security checks.

What is the x-middleware-subrequest Header?

The x-middleware-subrequest header is an internal Next.js header that prevents infinite loops. When middleware calls pages that also have middleware, this header tracks the chain.

If the same middleware appears 5+ times in the chain, Next.js stops running middleware to prevent stack overflow. The header stores middleware names separated by colons.

The vulnerability exists because Next.js trusts this header in all incoming requests, not just internal ones. By adding this header with five instances of “middleware”, attackers can trick Next.js into skipping the security checks entirely.

Next.js Versions Affected

The vulnerability affects all versions of Next.js from 11.1.4 to 15.2.2. The issue was fixed in the following versions:

Version RangeStatusAction
11.1.4 to 12.3.4VulnerableUpdate to 12.3.5 or newer
13.0.0 to 13.5.8VulnerableUpdate to 13.5.9 or newer
14.0.0 to 14.2.24VulnerableUpdate to 14.2.25 or newer
15.0.0 to 15.2.2VulnerableUpdate to 15.2.3 or newer
12.3.5+PatchedNo action needed
13.5.9+PatchedNo action needed
14.2.25+PatchedNo action needed
15.2.3+PatchedNo action needed

The patched versions now validate this header properly to prevent abuse from external requests.

References


Trevor I. Lasn

Trevor I. Lasn

Building whiteheap.com and 0xinsider.com.



Related Articles

Check out these related articles that might be useful for you. They cover similar topics and provide additional insights.

Security
4 min read

Add a Content Security Policy to an Astro site to block XSS: Astro 6's built-in CSP, the Astro CSP gotcha, and header setups for Vercel and Cloudflare.

Oct 16, 2024
Read article
Security
4 min read

HTTP CONNECT asks a proxy to open a TCP tunnel to a host, so HTTPS passes through still encrypted. How the method works, a Node.js client, and common pitfalls.

Nov 28, 2024
Read article
Security
3 min read

A CLI tool that checks packages for security issues and social engineering attacks before they hit your project

Jul 26, 2025
Read article
Security
8 min read

localStorage is vulnerable to XSS and has no expiry or encryption. Learn why httpOnly cookies and sessionStorage are safer for auth tokens.

Oct 28, 2024
Read article
Security
5 min read

Symmetric encryption algorithms like Advanced Encryption Standard (AES) are largely quantum-resistant already

Oct 31, 2024
Read article
Security
6 min read

Secretlint scans your code for API keys, tokens and passwords before they reach Git. Install it, run it in a pre-commit hook with Husky, and pick its rules.

Oct 22, 2024
Read article
Security
6 min read

BotID verifies browser challenges before proxying to the backend. Here's how I set it up in Next.js 16.

Feb 16, 2026
Read article
Security
5 min read

A Forrester study for Cloudflare found 39% of companies losing control of their IT and security, as remote work, cloud apps and new regulations pile up.

Oct 3, 2024
Read article
Security
13 min read

A frontend security checklist covering XSS, Content Security Policy headers, CSRF, insecure direct object references and exposed environment variables.

Jul 30, 2024
Read article

This article was originally published on https://www.trevorlasn.com/blog/cve-2025-29927-nextjs-middleware. It was written by a human and polished using grammar tools for clarity.