Next.js: Information disclosure across root params when a 'use cache' function is called through unstable_cache()
Affected releases · next
- 16.x16.3.0 – 16.4.4Fixed in 16.4.5
On 16.x, the newest line:
npm install next@16.4.5Every release on a timeline
Not affected
0.1.0 – 16.2.12
412 releases
Affected
16.3.0 – 16.4.4
14 releases
Fixed
16.4.5 – 16.4.6
2 releases
What happens
Next.js applications with 'use cache' can disclose cached data across root params when the same 'use cache' function is called both directly during rendering and through unstable_cache(), and that function reads a root param. Root params are route parameters of the root layout, and applications commonly use them to scope data, for example per locale.
During a cold process start, a cross-request deduplication race allowed an unstable_cache() call to join the in-flight fill of a concurrent direct call and receive its result, bypassing the root param check that would normally reject it. unstable_cache() then stored that result under a cache key without root params, so subsequent requests for other root param values received the same entry until it is revalidated or evicted. Cached data produced for one root param value is returned to requests for other values.
Exploitation requires the unstable_cache() request to arrive while the function's first fill after a process start is still in flight. Outside this race, the nesting already throws an error: 'use cache' inside unstable_cache() is unsupported, and avoiding it is a complete workaround.
A whole project to check? Paste its package.json in the dependency check: every deprecated, outdated or vulnerable dependency, with what to upgrade to. Free, no account.