Next.js: Unbounded next/image disk cache growth can exhaust storage
Affected releases · next
- 16.x16.0.0 – 16.1.6Fixed in 16.1.7
- 15.x15.0.0 – 15.5.13Fixed in 15.5.14
- 14.x14.0.0 – 14.2.35No fix on this line yet
- 13.x and older10.0.0 – 13.5.11No fix, no longer updated
On 16.x, the newest line:
npm install next@16.1.7Affected
16.0.0 – 16.1.6
19 releases
Fixed
16.1.7 – 16.4.2
26 releases, latest
Affected
15.0.0 – 15.5.13
68 releases
Fixed
15.5.14 – 15.5.28
14 releases
Affected
14.0.0 – 14.2.35
46 releases
Affected
13.0.0 – 13.5.11
56 releases
Affected
12.0.0 – 12.3.7
33 releases
Affected
11.0.0 – 11.1.4
7 releases
Affected
10.0.0 – 10.2.3
18 releases
Is your project affected?
Paste your package.json, or type the range you declare for next. It is read in your browser and sent nowhere.
What happens
Summary
The default Next.js image optimization disk cache (/_next/image) did not have a configurable upper bound, allowing unbounded cache growth.
Impact
An attacker could generate many unique image-optimization variants and exhaust disk space, causing denial of service. Note that this does not impact platforms that have their own image optimization capabilities, such as Vercel.
Patches
Fixed by adding an LRU-backed disk cache with images.maximumDiskCacheSize, including eviction of least-recently-used entries when the limit is exceeded. Setting maximumDiskCacheSize: 0 disables disk caching.
Workarounds
If upgrade is not immediately possible:
Periodically clean
.next/cache/images.Reduce variant cardinality (e.g., tighten values for
images.localPatterns,images.remotePatterns, andimages.qualities)