A Python script to test Next.js applications for middleware bypass vulnerabilities. The tool attempts various bypass techniques and captures screenshots when potential vulnerabilities are detected.
- Tests multiple middleware bypass techniques
- Automatic screenshot capture for successful bypasses
- Support for multiple subdomains
- SSL verification bypass
- Headless browser testing
- Custom header manipulation
- Clone the repository:
git clone https://github.com/narasimhauppala/nextjs-middleware-bypass/upload/main
cd nextjs-middleware-bypass- Install the required dependencies:
pip install -r requirements.txt- Create a file containing target URLs/subdomains (one per line):
example.com
subdomain.example.com
app.example.com
- Run the script:
python script.py -f targets.txtCreate a requirements.txt file with:
requests
selenium
webdriver-manager
urllib3
The script:
- Reads target URLs from the input file
- Tests each URL with various middleware bypass headers
- Captures screenshots when redirects (301, 302, 307, 308) are detected
- Saves screenshots in the
screenshotsdirectory
- middleware:middleware:middleware:middleware:middleware
- middleware:root
- middleware:nextjs
- pages/_middleware
- _next/data
- middleware:rewrite:middleware
- middleware:middleware
- middleware:pages
- _next/data/middleware
- next-middleware
- _next/static
The script provides detailed output for each test:
[*] Testing: https://example.com
[>] Testing URL: https://example.com
[>] Header: middleware:nextjs
Status Code: 307
Important Response Headers:
location: /redirect
x-nextjs-match: true
[!] Redirect Detected!
[>] Redirect Location: /redirect
[+] Screenshot saved: screenshots/example.com__middleware_nextjs__20240401-120000.png
Screenshots are saved in the screenshots directory with the following naming format:
{domain}__{header-value}__{timestamp}.png
This tool is for educational and security testing purposes only. Always obtain proper authorization before testing any websites or applications.
- Next.js Security Documentation
- CVE-2025-29927 Research