Skip to content
← All posts
·5 min read

Next.js Cache Poisoning: Your Cache Key Is Part of Your API Contract

Next.jsSecurityCachingMulti-tenant

On 3 November 2026, Next.js shipped a security release with seven fixes. Most of them were in the caching layer, and the most serious one could, under the right conditions, serve one tenant's cached response to a different tenant.

I keep relearning this lesson in different disguises: a cache key is part of your API contract, not an implementation detail. If the key doesn't encode who is asking, the system isn't really multi-tenant — it just hasn't leaked yet.

What actually broke

The headline issue involved combining the newer use cache directive with the older unstable_cache() API. When a use cache function that reads a root parameter (think [tenant] or [locale] at the top of your route tree) was also called through unstable_cache, a concurrent cold-cache fill could hand back another request's result without checking that the root parameters matched.

Read that again: two requests, a cold cache, a race — and tenant B gets tenant A's data.

Related fixes in the same release covered:

  • Different binary arguments producing the same cache key, so one user's result could be returned to another.
  • Cache entries leaking across root-param values in nested use cache functions.
  • A shared prerendered shell that could be poisoned on self-hosted next start apps using Cache Components.

The fixes ship in Next.js 16.4.5 and 15.5.29 (and later). If you use Cache Components or use cache, upgrade first and read the rest of this post second.

Why this is a boundary bug, not a caching bug

It's tempting to file this under "framework bug, upgraded, done." But every one of these issues has the same shape: the cache key didn't fully describe the inputs that make a response unique.

A function's output depends on its arguments and its context — the tenant, the user, the locale, the permissions. A cache that keys on only part of that context is quietly asserting "these requests are interchangeable." When that assertion is wrong, you don't get an error. You get someone else's data, served fast.

That's the same failure I watch for everywhere else in a system:

  • A webhook handler that trusts the payload without verifying the signature and which account it belongs to.
  • An adapter that accepts a loose object and lets callers smuggle in fields it never meant to accept.
  • An API route that checks "is the user logged in?" but not "does this user own this record?"

Each one is a boundary that doesn't encode who is on the other side. Caching is just one more boundary, and it's the one we tend to treat as plumbing.

What I check in my own projects

1. Make tenant context an explicit argument

If a cached function's result depends on the tenant, pass the tenant in as an argument rather than reading it implicitly from somewhere inside. Explicit inputs end up in the key; implicit context is where leaks hide.

// Risky: the tenant is read implicitly, so the key may not include it
async function getDashboard() {
  "use cache";
  const tenant = await getTenantFromSomewhere();
  return loadDashboard(tenant);
}
 
// Better: the tenant is an argument, so it is part of the cache key
async function getDashboard(tenantId: string) {
  "use cache";
  return loadDashboard(tenantId);
}

2. Don't mix caching APIs on the same function

The worst bug in this release lived in the overlap between unstable_cache and use cache. Pick one model per function. Two caching layers wrapped around the same data double the number of keys you have to reason about.

3. Never cache per-user data in a shared cache

Anything that depends on the current session — cart, dashboard, permissions — is per-user. Either key it by user explicitly or don't put it in a shared cache at all. Fast and correct beats very fast and occasionally someone else's.

4. Test the race, not just the happy path

Cache bugs rarely show up when you click around locally with one browser tab. Write a test that fires concurrent requests for different tenants at a cold cache and asserts that each one gets its own data back.

5. Stay on the latest patch release

This one is boring and it works. Next.js has shipped multiple security releases in 2026. Running a few patches behind is a risk, not just technical debt.

The takeaway

Caches are fast precisely because they decide that two requests are "the same." That decision is a security decision. Treat your cache keys the way you'd treat an auth check: write down what makes a request unique, put all of it in the key, and test the case where two different people ask at the same time.

If you're running a multi-tenant Next.js app and want a second pair of eyes on your caching or upgrade path, get in touch.

Sources: Next.js November 2026 security release · Netlify changelog: Next.js security release

Available for work