← Back to Pull requests

Add Next.js middleware authorization bypass scanner (CVE-2025-29927) #21566

Closed
unknown closed this pull request without merging on Jun 23, 2026 18:54 UTC
View on GitHub
unknown unknown commented on Jun 13, 2026 15:25 UTC
Author

Summary

Adds auxiliary/scanner/http/nextjs_middleware_auth_bypass, a detection module for
CVE-2025-29927 (CVSS 9.1) — an
authorization bypass in self-hosted Next.js applications.

Vulnerability

Next.js tags its own internal subrequests with the x-middleware-subrequest header
and skips middleware when it sees it. The header is trusted without verifying it
originated internally, so an external client that supplies it makes Next.js skip
middleware execution entirely — bypassing any authentication, authorization, or
redirects implemented in middleware.ts. The header value is the middleware module
name; on Next.js 13.2+ it must be repeated five times to satisfy the internal
recursion-depth check. Affected self-hosted versions: < 12.3.5, < 13.5.9,
< 14.2.25, < 15.2.3. (Vercel/Netlify-hosted apps are not affected — the platforms
strip the header.)

What the module does

This is a detection module (the impact is app-specific). It performs a
differential check against a user-supplied, normally middleware-gated path
(TARGETURI):

1. A baseline request that is expected to be gated (a redirect to login, or 401/403).
2. The same request with a crafted x-middleware-subrequest header (it iterates the
known per-version payloads).

If the gate disappears — the protected resource is served, or the middleware login
redirect is gone — the target is reported vulnerable. It only reports; it does not
act on the bypassed response.

Verification

Tested against minimal self-hosted Next.js apps (App Router, a middleware.ts that
redirects /dashboard to /login) at a vulnerable and a patched version:

msf6 auxiliary(scanner/http/nextjs_middleware_auth_bypass) > set TARGETURI /dashboard
msf6 auxiliary(scanner/http/nextjs_middleware_auth_bypass) > set RPORT 3000   # Next.js 15.2.2
msf6 auxiliary(scanner/http/nextjs_middleware_auth_bypass) > run
[+] 127.0.0.1:3000        - Next.js middleware authorization bypass confirmed (CVE-2025-29927): HTTP 307 -> /login -> HTTP 200 with x-middleware-subrequest 'middleware:middleware:middleware:middleware:middleware'

msf6 auxiliary(scanner/http/nextjs_middleware_auth_bypass) > set RPORT 3001   # Next.js 15.2.3 (patched)
msf6 auxiliary(scanner/http/nextjs_middleware_auth_bypass) > run
[*] 127.0.0.1:3001        - /dashboard gated (HTTP 307 -> /login); not bypassed (patched or not Next.js middleware)

Documentation with the full Docker lab setup and scenarios is included at
documentation/modules/auxiliary/scanner/http/nextjs_middleware_auth_bypass.md.

Verification Steps

1. Start a vulnerable self-hosted Next.js app with a middleware-gated route (see docs)
2. use auxiliary/scanner/http/nextjs_middleware_auth_bypass
3. set RHOSTS <target>
4. set TARGETURI <a middleware-gated path>
5. run — the module reports the bypass when the gate is removed under the header

Diff: 369 lines (+276 / -93) across 4 files Reviewer: kenlacroix Review duration: 14608m
All Vouch review confidence checks passed
Residual risk 0.28 = Change Risk (0.66) × (1 − Review Confidence (0.58)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.66 · 369 lines diff across 4 files
0.66
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
0.17
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
57%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.354
Shallow Review Depth shallow_review_depth
0.289
Sensitive Paths sensitive_paths
0.066
Real PR Conversation Timeline
1 comments
"Review active on #21566"
general weight: 0.35
Reviewers
Assignees
Unassigned
Labels
risk: low confidence: 58.0% reviewed sensitive_module
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 66.0% (HIGH) · Higher = larger blast radius
66.0%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 58.0% · Lower = rushed or shallow review
58.0%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 27.7% · Safe to merge
27.7%