Next.js has a Denial of Service in the Image Optimization API
Affected releases · next
- 16.x16.0.0 – 16.2.4Fixed in 16.2.5
- 15.x15.0.0 – 15.5.15Fixed in 15.5.16
- 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.2.5Affected
16.0.0 – 16.2.4
25 releases
Fixed
16.2.5 – 16.4.2
20 releases, latest
Affected
15.0.0 – 15.5.15
70 releases
Fixed
15.5.16 – 15.5.28
12 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
Impact
When self-hosting Next.js with the default image loader, the Image Optimization API fetches local images entirely into memory without enforcing a maximum size limit. An attacker could cause out-of-memory conditions by requesting large local assets from the /_next/image endpoint that match the images.localPatterns configuration (by default, all patterns are allowed).
If you are using
images.localPatterns, only the patterns in that array are impacted.If you are using
images.unoptimized: true, you are NOT impacted.If you are using
images.loader: 'custom', you are NOT impacted.If you are using Vercel, you are NOT impacted.
Fix
We now apply response size limits consistently to internal image fetches, not just external ones, and fail oversized responses before they can exhaust process memory.
This can be adjusted using the images.maximumResponseBody configuration.
Workarounds
If you cannot upgrade immediately, avoid routing large local assets through /_next/image, disable image optimization for large or untrusted local files, or block image optimization access to those assets at the edge.
You can disable using the images.localPatterns: [] configuration. This will still allow fetching remote images (which is not impacted).