Skip to content
Cache bugs Write-up Advanced

Nextjs Cache And Chains The Stale Elixir

Next.js incorrectly treated server-side rendered requests as static when the x-now-route-matches header was present, causing them to be cached with a long-lived cache-control. An attacker could poison the framework's internal cache to cause denial of service or stored cross-site scripting on pages that reflect request data.

zhero-web-sec.github.io

Published on zhero-web-sec.github.io

[] I was honored by the selection of this paper as the 7th best web research in PortSwigger’s top 10 web hacking techniques of 2025.

The author, on zhero-web-sec.github.io

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

How it worked

Impact

An attacker could poison the cache to cause denial of service by serving JSON instead of HTML, or achieve stored XSS if any request value is reflected, potentially leading to data theft or account takeover; the attack works without an external cache and affects default deployments.

What the attacker needed

Next.js 13.5.1 to 14.2.9; Pages router; Non-dynamic SSR route; No external cache required

The fix

The vulnerability was fixed in Next.js version 14.2.9, but the __nextDataReq parameter issue remains unfixed.

How it was found

  1. Send a request to a server-side rendered endpoint with the __nextDataReq URL parameter to make it a data request.
  2. Add the x-now-route-matches header to make the framework treat the request as static and cacheable.
  3. Wait for the cache to store the response, then access the endpoint normally to see the poisoned JSON or HTML.
  4. For stored XSS, include a reflected value (such as the user-agent) containing an HTML payload in the poisoning request.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

Next.js is a tool for building websites. It has a built-in cache to speed up pages that don't change often. The bug let an attacker trick the cache into storing a page that should never be cached, so other visitors would see the attacker's version, which could break the site or run malicious code.

What is Cache bugs?

A cache and the origin disagree about a request, so a poisoned response is served to everyone or a private page is stored as public.

Similar reports

View all

Same bug class and techniques, clearest first.

Web cache poisoning and deception

The lesson behind this report.

A cache and the origin disagree about a request, so a poisoned response is served to everyone or a private page is stored as public.