## https://sploitus.com/exploit?id=D8581565-23A3-56A4-AD8A-50F991DDE1F2
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
</head>
<body>
<h1>CVE-2025-29927: Next.js Middleware Authorization Bypass Simulation</h1>
<p>
This repository demonstrates the exploitation of <strong>CVE-2025-29927</strong>, a critical vulnerability in Next.js that allows attackers to bypass middleware-based authorization checks. The flaw stems from improper handling of the internal <code>x-middleware-subrequest</code> HTTP header, enabling unauthorized access to protected routes.
</p>
<h2>โ ๏ธ Disclaimer</h2>
<p>
This project is intended for educational and research purposes only. Unauthorized use against systems without explicit permission is illegal and unethical. The authors are not responsible for any misuse of this code.
</p>
<h2>๐ Background</h2>
<p>
<strong>CVE-2025-29927</strong> affects Next.js versions prior to:
</p>
<ul>
<li>12.3.5</li>
<li>13.5.9</li>
<li>14.2.25</li>
<li>15.2.3</li>
</ul>
<p>
The vulnerability arises when an attacker includes the <code>x-middleware-subrequest</code> header in an HTTP request. Next.js interprets this header as an internal subrequest, causing it to skip middleware execution, including critical authorization checks.
</p>
<h2>๐งช Simulation Setup</h2>
<h3>Prerequisites</h3>
<ul>
<li>Node.js (v14 or later)</li>
<li>npm</li>
</ul>
<h3>Installation</h3>
<ol>
<li>Clone the repository:
<pre><code>git clone https://github.com/Knotsecurity/CVE-2025-29927-NextJs-Middleware-Simulation.git
cd cve-2025-29927-simulation</code></pre>
</li>
<li>Install dependencies:
<pre><code>npm install</code></pre>
</li>
<li>Start the development server:
<pre><code>npm run dev
</code></pre>
</li>
</ol>
<h2>๐ Vulnerability Demonstration</h2>
<h3>Protected Route</h3>
<p>
The application includes a protected route at <code>/admin</code>, which is guarded by middleware that checks for user authentication.
</p>
<h3>Exploitation Steps</h3>
<ol>
<li>Access the <code>/login</code> page and log in with <code>user@example.com:password123</code>.</li>
<li>Try to access the <code>/admin</code> page. You will get an unauthorized access error.</li>
<li>Capture this request in Burp Suite and add the header <code>x-middleware-subrequest: middleware</code>, then send the request.</li>
<li>You will observe that you now have access to the <code>/admin</code> page.</li>
</ol>
<h2>๐ก๏ธ Mitigation</h2>
<p>To protect against this vulnerability:</p>
<ol>
<li><strong>Upgrade Next.js</strong> to a patched version:
<pre><code>npm install next@latest</code></pre>
</li>
<li><strong>Filter Requests:</strong> Configure your server or proxy to reject requests containing the <code>x-middleware-subrequest</code> header.</li>
<li><strong>Redundant Checks:</strong> Implement authorization checks within your route handlers, not solely in middleware.</li>
</ol>
<h2>๐ References</h2>
<ul>
<li><a href="https://github.com/vercel/next.js/security/advisories/GHSA-f82v-jwr5-mffw">Next.js Security Advisory</a></li>
<li><a href="https://www.akamai.com/blog/security-research/march-authorization-bypass-critical-nextjs-detections-mitigations">Akamai Blog on CVE-2025-29927</a></li>
<li><a href="https://securitylabs.datadoghq.com/articles/nextjs-middleware-auth-bypass/">Datadog Analysis</a></li>
</ul>
<h2>๐งโ๐ป Author</h2>
<p>
<a href="https://github.com/sh311InP4r4diz3">Saikiran B</a>
</p>
</body>
</html>