Skip to the page

Caching in Next.js 16 · senior

Cross-user data leaks through caching

Two users seeing each other's data usually means user-specific output was cached without the user in the key, a route was made static while rendering per-user data, module-level state was shared across requests, or a CDN cached a personalised response.

The notes

What you must know

  • Cause 1: user data inside "use cache" (or a cached fetch) without the user id as an argument. Fix: read the session outside and pass the id in, or use "use cache: private".
  • Cause 2: module-level variables on the server (a store, a Map, a "current user" variable) are shared by every request in that process.
  • Cause 3: a route accidentally static/ISR while it shows personalised content.
  • Cause 4: a CDN or proxy caching responses that depend on cookies. Dynamic Next.js pages send Cache-Control: private, no-cache, no-store; do not override it; use Vary correctly.
  • Nov 2026 security release (16.4.5 / 15.5.29) fixed cross-tenant leaks in Cache Components apps: unstable_cache + "use cache" reading root params, nested "use cache" functions reading root params, binary arguments colliding in cache keys, and shell poisoning on self-hosted next start without Partial Prefetching. Patch promptly.
  • Prevention: regression tests with two sessions, ensureStatic on routes that must be static (and never personalised), review rule "no session data in a cached scope unless it is an argument", per-request stores.
  • "Clear the cache" is not a fix; find which layer mixed users.

The red pen

Common traps: mistake → fix

  • Mistake: "Caching is safe because the URL is the same for everyone"

    Fix: the content is not.

  • Mistake: "Module variables are per user because each request calls the function"

    Fix: the module is loaded once per server process.

  • Mistake: "Just disable caching globally"

    Fix: hides the bug and kills performance.

Easy to hard

Questions interviewers ask, easy to hard

  1. Two users report seeing each other's dashboard data. What are the likely causes in a Next.js app?
  2. How can a route accidentally become static?
  3. What is wrong with a module-level store on the server?
  4. What did the November 2026 Next.js security release fix?
  5. How do you prevent this from happening again?

Explain it out loud

Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.

Practise by voice

Your first interview is free

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview