DEV Community

Cover image for Next.js Response Injection: The Bug Behind CVE-2026-119348
Parsa J
Parsa J

Posted on Originally published at bestpractic.org

Next.js Response Injection: The Bug Behind CVE-2026-119348

On November 3, 2026, the Next.js team shipped 16.4.5 as a security release. Buried among seven fixes is GHSA-pc58-hwjq-p385 (CVE-2026-119348): a self-hosted App Router app that forwards a fetched upstream response unchanged — through a Route Handler, or through the fetch cache replaying one — can leak framing headers that don't match the body it actually sends. Sit that app behind an HTTP/1.1 reverse proxy that queues pipelined responses on a shared backend connection, and a crafted upstream response can desynchronize two clients' responses: one tenant's browser ends up holding bytes meant for someone else's request.

This is written against Next.js 16.4.5 (verified against the framework's own GitHub security advisory, published November 3, 2026; affected versions are 16.0.0 through 16.4.4 and 15.5.28 and below). If you're not pinned to an old version, npm install next@latest already closes it — the advisory rates it Moderate (CVSS v4 6.3) and names no working exploit in the wild. What's worth your time is why this class of bug exists at all, because the mechanism has nothing to do with a Next.js mistake in the usual sense. It's the oldest trick in HTTP — response splitting — and Next.js earns a chapter in that story only because fetch() makes "just return the upstream response" one line of code, which is exactly how this family of bugs always gets in.

What you'll learn

By the end of this article you'll be able to:

  • Explain what an HTTP/1.1 connection's "framing" is, and why Content-Length and Transfer-Encoding are promises a server makes to whoever reuses that connection next
  • Explain exactly what CVE-2026-119348 is (and isn't): what "forwarding a response unchanged" means in an App Router Route Handler and in the fetch cache
  • Reproduce, conceptually, how a reverse proxy pipelining requests over one shared backend connection can hand one client's browser a different client's response
  • Audit your own Route Handlers for the pattern that makes this bug possible, independent of whether you're already patched
  • Write a Route Handler that proxies an upstream response safely, by habit, not by luck

Who this is for: you're building App Router Route Handlers that call out to another API and return its response — a BFF layer, an image proxy, a webhook relay, anything that sits in front of someone else's service. If Route Handler caching itself is new to you, this series' Route Handlers get stopped caching covers the basics first — worth reading before this one, not required. If you run Next.js behind your own reverse proxy rather than a managed platform, the network-boundary model in Next.js proxy.ts Explained is useful background too.

Contents

The bug, shown wrong-way-first

Say you're building a Route Handler that fronts an internal pricing API, so the browser only ever talks to your own domain:

// app/api/price/[sku]/route.ts — the "just forward it" version
export async function GET(
  req: Request,
  { params }: { params: Promise<{ sku: string }> }
) {
  const { sku } = await params
  const upstream = await fetch(`https://pricing.internal/v1/price/${sku}`)
  return upstream // hand the Response straight back to the browser
}
Enter fullscreen mode Exit fullscreen mode

This looks completely reasonable, and for a single isolated request it behaves correctly: the status, body, and headers from pricing.internal reach the browser untouched. The App Router happily accepts a Response object returned from a Route Handler — that's the documented, idiomatic way to return a response at all.

The gap is what "untouched" includes. The upstream response's framing headers — the ones that tell whatever is holding the TCP connection where this response's body ends and the next one begins (Content-Length, Transfer-Encoding: chunked, Connection) — are forwarded along with everything else. Your Route Handler never built its own framing; it's reusing whatever pricing.internal sent, and trusting it to accurately describe the bytes that follow.

Deploy this behind an HTTP/1.1 reverse proxy that pipelines requests — queues several clients' requests onto one shared keep-alive connection to your Next.js server to save on connection overhead — and that trust becomes the whole bug. GHSA-pc58-hwjq-p385 describes exactly this shape: "a crafted upstream response can desynchronize responses between clients," letting one client's request receive "response injection and disclosure of other clients' responses." The official advisory stops there deliberately — it names the mechanism (framing headers that don't match the body sent) and the precondition (a pipelining HTTP/1.1 reverse proxy on a shared backend connection) without publishing a working repro, which is normal disclosure practice for a bug in this class. What it hands you instead is enough to understand why the pattern above is dangerous, which is the useful part anyway: the fix is one npm install, but the pattern that caused it is something you're probably still writing today, patched or not.

The mental model: a connection is a shared pipe, and framing is the only fence

The mental model: an HTTP/1.1 keep-alive connection is a single ordered byte stream carrying multiple request/response pairs back to back, with no built-in boundary markers between them. The only thing separating "response A ends here" from "response B starts here" is a promise the server makes in its own headers — Content-Length: N ("read exactly N bytes and stop") or Transfer-Encoding: chunked (a series of self-describing length-prefixed chunks ending in a zero-length chunk). Whoever is reading that stream — a browser, or a reverse proxy multiplexing several clients onto one backend connection — has to take that promise at face value, because the wire gives it nothing else to go on.

That promise is also the whole attack surface of the response-splitting / response-desync bug family (tracked more generally as CWE-444, "Inconsistent Interpretation of HTTP Requests"): if the declared framing disagrees with the bytes actually sent — say the header claims a Content-Length shorter than the real body — the reader stops reading where the header says to, and treats the leftover bytes as the start of the next response on the connection. On a connection serving one client, that's merely a parsing bug. On a shared, pipelined connection serving several clients' queued requests, those leftover bytes are the beginning of someone else's conversation — which is precisely the "cross-client" half of this advisory's name.

Next.js doesn't invent this bug class; it just hands you, via fetch(), an unusually easy way to opt into trusting an upstream's framing instead of generating your own. Every reverse proxy and every API gateway has to solve this same problem, and the standard answer is the same everywhere: never let an upstream's framing headers reach the client verbatim. Regenerate the response you send, and let your own runtime compute its own framing from the body you actually serve.

Staged walkthrough: from one fetch() call to a cross-client leak

Stage 1 — the single-request view (looks fine). One client, one request, one response. fetch() returns a Response, your handler returns it, the browser renders it. Nothing here reveals the bug, because a single unshared connection has no second response to collide with.

const upstream = await fetch(url)
return upstream
Enter fullscreen mode Exit fullscreen mode

Key concept: a Response object carries its headers as a live Headers instance, and returning it verbatim means every header the upstream sent — including the ones that only make sense on that connection, between that pair of servers — rides along to the browser.

Stage 2 — add a shared, pipelined connection. This is the precondition the advisory names explicitly, not a hypothetical: "an app sits behind an HTTP/1.1 reverse proxy that permits pipelined response queueing" on a connection to the backend shared across clients. Picture two requests, from two different browsers, queued through the proxy onto the same keep-alive connection to your Next.js server: request A, then request B, back to back, same socket.

Stage 3 — the upstream response disagrees with its own framing. Your Route Handler's fetch() call to the internal API gets back a response whose declared length doesn't match its real body — crafted, buggy, or simply mis-proxied upstream of you. You forward it unchanged. The reverse proxy, reading strictly by the framing header it was told to trust, stops reading response A's body exactly where that header says to — which is before the real end of the bytes Next.js actually wrote to the socket.

Stage 4 — the leftover bytes become someone else's response. Whatever Next.js wrote after the point the proxy thought response A ended is still sitting on the connection. The proxy, having already moved on to deliver request B's turn, reads those leftover bytes as the start of response B — and hands client B a response built partly or wholly from client A's data. This is the "disclosure of other clients' responses" the advisory describes, and depending on exactly how the bytes land, it can go the other way too: a crafted response can inject content into a connection it was never meant to answer.

Key concept: nothing about steps 3–4 requires a bug in Next.js's own rendering, routing, or caching logic. The entire mechanism lives in the gap between "what the framing header claims" and "what bytes were actually written" — a gap that only opens because step 1 forwarded an upstream's framing headers instead of generating fresh ones.

Edge cases

  • The fetch cache, not just Route Handlers. The advisory's title names both "App Router route handlers" and "the fetch cache" as paths to this bug. A cached fetch() result that gets replayed later carries the same risk if what's replayed includes the original framing headers rather than a freshly computed response — the vulnerable pattern is "store and replay an upstream response's own header set," wherever in your app that happens.
  • Not every reverse proxy is affected. The advisory is specific: the precondition is an HTTP/1.1 proxy that does pipelined response queueing on a shared backend connection. A proxy that opens one backend connection per client request, or that terminates HTTP/1.1 and speaks HTTP/2 or HTTP/3 to clients while multiplexing properly on the backend, doesn't have the "leftover bytes land in someone else's turn" step that makes this dangerous. If you don't know which your platform does, treat yourself as in scope and patch anyway — the fix costs nothing and the alternative is finding out the hard way.
  • Managed hosting isn't automatically exempt. The advisory's own framing is "self-hosted," and some platforms have stated their specific proxy architecture isn't affected. That is a statement about one piece of infrastructure, not a blanket guarantee for every hosting target — verify your own platform's advisory, don't assume.
  • This is a Moderate-severity, high-complexity bug, not a trivial one. The CVSS v4 vector lists AC:H (high attack complexity) and AT:P (attack requirements present) — exploitation needs the specific proxy behavior lined up, not just an internet connection. That earns "patch promptly," not "panic."

Best practices

  • Never return a fetched Response to the client unchanged. Build your own: read what you need from the upstream (.json(), .text(), or stream the body if you must), and construct a fresh Response with exactly the headers your own API contract requires. Let the runtime compute Content-Length or chunk the body itself — don't copy the upstream's framing headers into yours.
  const upstream = await fetch(url)
  const data = await upstream.json()
  return Response.json(data, {
    status: upstream.status,
    headers: { "cache-control": "no-store" }, // only headers you intend to set
  })
Enter fullscreen mode Exit fullscreen mode
  • If you must stream a large body through, still don't trust the upstream's own framing. Stream upstream.body into a response you construct, with headers you set explicitly — not new Response(upstream.body, { headers: upstream.headers }), which carries the same risk the advisory describes.
  • Treat hop-by-hop headers as never-forward, always. Connection, Transfer-Encoding, Content-Length, Keep-Alive: these describe the upstream's own connection to its caller, not yours to the browser. If you need to pass through headers wholesale for a legitimate proxy use case, allow-list the ones you actually need instead of spreading everything.
  • Know whether your reverse proxy pipelines on a shared backend connection. This is an infrastructure question, not a Next.js one — ask your platform or your ops team, and if you don't get a clear answer, patch and move on regardless.
  • Patch on a schedule, not on a hunch. A Moderate, high-complexity CVE like this one is exactly what dependency update automation (Dependabot, Renovate) exists for. Don't wait for a deep-dive to tell you to run npm install next@latest — this article is about the mechanism, not a substitute for routine patching.

FAQ

Is my app vulnerable if I don't run any Route Handlers?

Possibly still yes, per the advisory's own wording: the fetch cache replaying a previously fetched upstream response is named as a second path to the same bug, independent of whether you write Route Handlers yourself. Patching to 16.4.5 (or 15.5.29) closes both paths; the defensive pattern in this article (never forward upstream framing headers) is the thing to also apply by hand anywhere your own code constructs a response from an upstream fetch.

Does this affect the Pages Router too?

The advisory's affected-versions list includes 15.5.28 and below, which predates the App Router being the default, so Pages Router apps that proxy upstream responses through an API route are not automatically exempt from the underlying pattern — the same "don't forward upstream framing headers" rule applies there. Check your specific setup against the advisory rather than assuming either router is safe by default.

Is this the same bug as the unstable_cache cross-tenant leak from the same release?

No — they're two separate advisories in the same November 3, 2026 security release. GHSA-mfr8-8qww-v76h (covered in this series' unstable_cache root-param leak episode) is a cache-key bug: a "use cache" function's key didn't account for a root param it read. This one, GHSA-pc58-hwjq-p385, is a connection-level HTTP framing bug with nothing to do with cache keys. Both are fixed by the same 16.4.5 upgrade.

Do I need a specific reverse proxy to be at risk?

The advisory names the precondition precisely: an HTTP/1.1 reverse proxy that performs pipelined response queueing over a connection shared by multiple clients to your backend. If you don't control or can't confirm your proxy's behavior, the safe assumption is "maybe," and the fix — upgrading, plus never forwarding upstream framing headers by habit — costs nothing to apply regardless of the answer.

Was this exploited before it was patched?

The GitHub security advisory for GHSA-pc58-hwjq-p385 does not claim or document any known exploitation; it describes the vulnerability class, the precondition, and the fixed versions. Treat the absence of a reported incident as exactly that — an absence of a reported incident, not a guarantee.

🎮 Try it yourself

▶️ Open the interactive playground →

Runs right in your browser — poke at it and watch the concept react live.

Cheat sheet

Situation Do this Why
Route Handler calls fetch() and wants to send the result to the browser const data = await upstream.json(); return Response.json(data, { status: upstream.status }) You build fresh framing headers; nothing from upstream's Content-Length/Transfer-Encoding survives
You must stream a large upstream body through return new Response(upstream.body, { status: upstream.status, headers: pickedHeaders }) with pickedHeaders an explicit allow-list you built yourself Streaming is fine; forwarding the upstream Headers object wholesale is the risky part
Replaying a previously fetched response from your own cache Store the data, not the raw Response/Headers; reconstruct the response at serve time A stored response can carry the same stale/mismatched framing the advisory describes
Checking if you're affected npm view next version — anything 16.0.0–16.4.4 or ≤15.5.28 is affected Advisory GHSA-pc58-hwjq-p385, CVE-2026-119348
Fixing it npm install next@latest (or pin ≥16.4.5 / ≥15.5.29) Confirmed-patched versions per the official advisory
Headers that should never be copied from an upstream response Content-Length, Transfer-Encoding, Connection, Keep-Alive These describe the upstream's connection to its caller, not yours to the browser

🧠 Test yourself

Think it clicked? Take the 8-question quiz →

Instant feedback, a hint on every question, and an explanation for each answer — right or wrong.

Key takeaways

  • An HTTP/1.1 connection has no built-in message boundaries — only the framing headers a server declares (Content-Length, Transfer-Encoding). A shared, pipelined connection makes a framing mismatch a cross-client problem, not just a parsing one.
  • CVE-2026-119348 isn't a Next.js logic bug — it's response splitting, reached via fetch(). Any Route Handler or cached-fetch replay that forwards an upstream Response unchanged carries its framing headers along for the ride.
  • The fix that matters beyond the patch: never forward an upstream response's framing headers to the client. Build your own Response, from data you've read, with headers you chose — every time you proxy.
  • Upgrade to 16.4.5 / 15.5.29, and audit any Route Handler or cache-replay code that does return upstreamResponse or spreads upstream.headers wholesale.

You patched this one with an npm install. The pattern that made it possible — trusting someone else's framing because fetch() made it one line to forward — is still sitting in a lot of codebases that have never heard of this CVE and never will, until their own proxy starts pipelining. Go check your Route Handlers.

What's the first return upstream in your own code that you're now going to rewrite?

📚 Read next


🚀 Want more like this? Every guide, playground, and quiz lives on bestpractic.org — open it and sign up free so the next one finds you.

Thanks for reading! Let's stay connected:

Top comments (0)