CVE-2025-57822 PoC and fix: the Next.js middleware SSRF from NextResponse.next()

CVE-2025-57822 is a server-side request forgery in self-hosted Next.js before 14.2.32 and 15.4.7. It needs a mistake in your middleware: copying the visitor's request headers into the response with NextResponse.next({ headers: request.headers }). A stranger can then make the server fetch an address of their choice. Upgrade, and forward headers with NextResponse.next({ request: { headers } }).

The team behind Keybrum's attacksUpdated 9 min read
CVE-2025-57822medium · CVSS 6.5
Component
Next.js middleware (NextResponse.next and Location header handling) (next)
Affected
Next.js before 14.2.32 and 15.0.0 to 15.4.6, self-hosted, only when middleware passes request headers into the response
Fixed in
14.2.32, 15.4.7. Current patches: 16.4.5 or 15.5.29
Published
August 29, 2025
Does it reach a version you install? Drop your lockfile in the dependency checker: it reads every package, this one included.

In short

  • The flaw needs two things: Next.js before 14.2.32 or 15.4.7, and middleware that copies the visitor's request headers into its response, for example NextResponse.next({ headers: request.headers }).
  • With both, a stranger sends a request with a forged Location header and your server fetches that address and returns the page: internal services, cloud metadata, anything the server can reach.
  • Vercel's bulletin speaks of self-hosted deployments and says apps it hosts are not exploitable, with a platform patch on 25 August 2025. The researcher's write-up shows the same pattern exposing the OIDC token of a website hosted on Vercel.
  • Fixed in 14.2.32 and 15.4.7, published on 18 August 2025. In November 2026 the supported patches are 16.4.5 and 15.5.29.
  • The upgrade removes the SSRF. The middleware mistake stays and still sends every request header back to the browser, so fix the code too.
On this page

What CVE-2025-57822 is, in plain words

Middleware is the function Next.js runs before a request reaches a page or a route. Most middleware ends with NextResponse.next(), which means: carry on. That call accepts options, and two of them look alike.

CallWhat it does
NextResponse.next({ request: { headers } })Forwards the headers upstream, to your page or route. The browser never sees them. This is the documented way to pass data along
NextResponse.next({ headers })Sets the headers on the response, the one that goes back to the browser. The Next.js docs call this not good practice and say to avoid it
From the NextResponse page of the Next.js docs.

Developers who wanted the first sometimes wrote the second, with the visitor's own headers: NextResponse.next({ headers: request.headers }). Every header the visitor sent then became a response header of the middleware. Among the headers a visitor can send is Location, the header a server uses to announce a redirect.

Next.js read the middleware's response headers to decide what to do next. Before the fix, a Location header there was taken as the address that should handle the request, whatever the status code. The fix commit states the rule that was missing: when middleware sets a Location header, Next.js should not assume the target is the one to handle the request, and should only route there when a rewrite is explicitly triggered. The result is server-side request forgery (SSRF): the stranger names an address, and your server fetches it.

What a stranger can do with it

Your app, on an affected versionWhat a request with no login can do
Self-hosted, middleware reflects request headers on the routes it coversMake the server fetch any address it can reach and return the page: services on localhost, the private network, the cloud metadata service
The same, on a cloud virtual machine with unauthenticated metadataRead the machine's temporary cloud credentials
Middleware uses NextResponse.next() with no options, or with request: { headers }Nothing through this CVE: no visitor header reaches the middleware's response
Any app, after the upgrade, with the mistake still in the codeNo SSRF, but every request header is echoed in the response, including the ones your proxy or platform adds on the way in, which the visitor was never meant to see

The researcher who reported the flaw, Dominik Prodinger of RootSys, shows in his write-up that the attacker reads the full response: the application fetched the target address and returned the resulting page.

Severity, proof of concept and exploitation status

Two scores exist. GitHub, the numbering authority for the Next.js maintainers, gives 6.5, medium (AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:L/A:N): the high attack complexity stands for the condition the attacker does not control, your middleware. NVD gives 8.2, high (AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:L/A:N). If the pattern is in your code, the NVD number is the one that describes your app.

Who is affected

ConditionExposedNot exposed
Next.js versionEverything before 14.2.32, and 15.0.0 to 15.4.614.2.32 and later 14.x, 15.4.7 and later, 16.x
Middleware codeRequest headers passed into the response: NextResponse.next({ headers: request.headers }) or a copy of themNo middleware, or middleware that follows the documented request: { headers } form
HostingSelf-hosted: next start, the standalone output, a containerVercel says apps it hosts are not exploitable, with a platform patch dated 25 August 2025

On hosting, the two sources do not tell the same story. Vercel's bulletin limits the issue to self-hosted deployments. The researcher's write-up shows a website hosted on Vercel exposing its OIDC token through the same pattern. Today's state is not in dispute: the framework is fixed since 14.2.32 and 15.4.7, and Vercel says its platform is patched since 25 August 2025.

Apps built with AI tools

The two forms differ by one level of nesting, and both make the site work. A request to add the current path to the headers, or to pass the user id to the page, can produce either one, and nothing fails when it is the wrong one. If an AI tool wrote your middleware.ts, read the last line of the function. It takes a minute.

How to check your own app

bash
# 1. Installed version: use the line for your package manager
npm ls next
pnpm why next
yarn why next

# 2. Every NextResponse.next call that takes options
grep -rn "NextResponse.next(" --include=middleware.* --include=proxy.* --exclude-dir=node_modules .

# 3. Response headers built from the request
grep -rn "headers: req" --include=middleware.* --include=proxy.* --exclude-dir=node_modules .
Affected: before 14.2.32, or 15.0.0 to 15.4.6. In the grep output, headers at the top level of the options is the response; headers inside request is the documented form.

Look past the exact spelling. A new Headers(request.headers) that is later passed as response headers, or a loop that copies request headers onto response.headers, is the same mistake.

Keybrum has no attack that sends the forged header of CVE-2025-57822, so the version and the grep above are the test. It does prove the neighbours on a live app whose owner proved ownership: web.ssrf gives every URL-shaped route of your app a unique callback address, then the cloud metadata address, and web.nextjs-middleware-bypass checks whether pages behind middleware open without a session (CVE-2025-29927).

How to fix CVE-2025-57822

Two changes: the version and the code.

The first fixed versions are 14.2.32 and 15.4.7, published on 18 August 2025. They are a floor. The Next.js support policy lists 14.x as unsupported, and 15.4.7 is still exposed to later CVEs such as React2Shell, fixed in 15.4.8. The security release of 3 November 2026 ships 16.4.5 and 15.5.29: move to one of those.

bash
npm install [email protected]
# or, to stay on 15
npm install [email protected]
Commit the lockfile, rebuild and redeploy. Next.js 16 renames middleware.ts to proxy.ts; the upgrade guide covers the change.

Then fix the middleware, on any version:

ts
import { NextResponse, type NextRequest } from 'next/server'

// Before: every header the visitor sent becomes a response header
export function middleware(request: NextRequest) {
  return NextResponse.next({ headers: request.headers })
}

// After: headers go upstream to the page, not back to the browser
export function middleware(request: NextRequest) {
  const headers = new Headers(request.headers)
  headers.set('x-pathname', request.nextUrl.pathname)
  return NextResponse.next({ request: { headers } })
}
Keep one of the two functions. The second is the documented form: request: { headers } forwards headers to your page or route and does not expose them to the client.

If you cannot upgrade today

Fixing the middleware code is the workaround: with no visitor header in the middleware's response, the flaw has nothing to work with. Vercel's bulletin lists it first, pass the request explicitly, and adds two rules: do not forward user-controlled headers downstream without validation, and do not reflect headers such as Location through NextResponse.next. A reverse proxy that removes a Location header from incoming requests adds a second barrier, since browsers never send one.

What to do after upgrading

  1. 1

    Confirm production runs the fixed version

    Open your live site, open the browser console and type next.version. On a server you manage, make sure no old container still answers.

  2. 2

    Check that nothing is echoed back

    Send your own site a request with a made-up header and read the response headers: curl -sI -H 'x-echo-test: 1' https://your-app.example/. If x-echo-test comes back, the reflection is still there. Response headers should be ones you chose, such as security headers and cookies, never a copy of the request.

  3. 3

    Forward a short list, not everything

    The Next.js docs advise against copying all incoming headers, because that can leak sensitive data to clients or upstream services. Build the forwarded set from an allow list.

  4. 4

    Limit what the server can reach

    On a cloud virtual machine, require a session token on the metadata service (IMDSv2 on AWS) and deny outbound traffic to internal networks where you can. The next SSRF then finds less.

  5. 5

    Keep authorization out of middleware alone

    Middleware is a convenient place for redirects and a fragile place for security decisions. The Next.js security guide explains where the checks belong.

CVEWhat it doesFixed in
CVE-2024-34351SSRF through a Server Action that redirects, with a forged Host header14.1.1
CVE-2025-29927An internal header makes Next.js skip middleware15.2.3, 14.2.25, 13.5.9, 12.3.5
CVE-2026-44578SSRF through a crafted WebSocket upgrade on self-hosted servers, no mistake in your code needed15.5.16, 16.2.5
CVE-2026-94483SSRF through the image optimizer and an allowed host whose DNS the attacker controls16.3.8

Timeline

DateEvent
21 February 2025RootSys reports the issue to Vercel, according to the researcher's write-up
5 March 2025The report is closed as not specific to the framework, according to the same write-up
13 August 2025Fix commit lands in the Next.js repository
18 August 2025Next.js 15.4.7 and 14.2.32 published on npm
25 August 2025Vercel patches its platform
29 August 2025Advisory GHSA-4342-x723-ch2f, CVE record and Vercel's bulletin published
2 September 2025CISA's assessment: exploitation none
21 September 2025The researcher publishes his write-up
13 November 2026Still absent from CISA's Known Exploited Vulnerabilities catalog

Questions

Is there a public PoC for CVE-2025-57822?

The researcher who reported it published a write-up on 21 September 2025 that demonstrates the flaw, and Intigriti's write-up of its August 2025 capture-the-flag challenge covers the same CVE. CISA rated exploitation as none on 2 September 2025 and has not listed the CVE as exploited. This page does not reproduce the request: check your version and grep your middleware instead.

Are apps on Vercel affected by CVE-2025-57822?

Vercel's bulletin says apps it hosts are not exploitable, and that a platform patch was applied on 25 August 2025. The researcher's write-up shows the same pattern exposing the OIDC token of a website hosted on Vercel. Fix the middleware either way: the mistake still sends request headers back to the browser.

Am I affected if my middleware only calls NextResponse.next() with no options?

No. The flaw needs visitor-controlled headers in the middleware's response. NextResponse.next() with no options, or with request: { headers }, puts none there. Upgrade Next.js anyway for the other CVEs fixed since.

Which Next.js version fixes CVE-2025-57822?

14.2.32 and 15.4.7, published on 18 August 2025. Those are old in November 2026: the current security releases are 16.4.5 and 15.5.29, and the Next.js support policy lists 14.x as unsupported.

What is the difference between headers and request.headers in NextResponse.next()?

NextResponse.next({ request: { headers } }) forwards headers upstream to your page, route or Server Action without showing them to the browser. NextResponse.next({ headers }) sets them on the response sent to the browser. The Next.js docs say the second is not good practice and should be avoided.

Is Next.js 16 affected?

No. The affected range ends before 15.4.7, and 16.0.0 shipped in October 2025 with the fix. Check your proxy.ts for the same pattern anyway: reflecting request headers to the browser is a leak on any version.

Sources

  1. 1.GHSA-4342-x723-ch2f: Next.js Improper Middleware Redirect Handling Leads to SSRF, Vercel (Next.js) on GitHub
  2. 2.CVE-2025-57822, NIST National Vulnerability Database
  3. 3.CVE-2025-57822, CVE Program
  4. 4.CVE-2025-57822 bulletin, Vercel
  5. 5.fix router handling when setting a location response header (fix commit), Vercel (Next.js) on GitHub
  6. 6.NextResponse: next(), Next.js Docs
  7. 7.Next.js and the Mutated Middleware, Dominik Prodinger, RootSys
  8. 8.August CTF challenge: exploiting SSRF via Next.js middleware, Intigriti
  9. 9.November 2026 Security Release, Next.js Blog
  10. 10.Next.js support policy, Next.js
  11. 11.Known Exploited Vulnerabilities Catalog, CISA
  12. 12.EPSS score for CVE-2025-57822, FIRST

Keep reading

Your app is public. So are its mistakes.

Check what any attacker can already see in it, free, in ten seconds. The full attack, with proof and fixes: €49 once, or €29 a month on a plan.

or continue with Google or GitHub