Executive brief
Next.js's image optimization feature uses the libheif library (via the sharp library) to process AVIF image files. A crafted malicious AVIF file can trigger a heap buffer overflow when processed, allowing an unauthenticated remote attacker to execute arbitrary code on the server. This affects any Next.js application that automatically optimizes images, enabling complete system compromise.
Technical details
The vulnerability is a heap buffer overflow in libheif's scale_nearest_neighbor() function, triggered by a specially crafted AVIF file containing nested identity-derivation (iden) and auxiliary (auxl) item references. The attack chains four conditions: (1) transfer_channel_from_image_as() accepts duplicate destination channels without validation; (2) find_storage_for_channel() returns only the first match, causing mismatch between declared and actual channel bit depths; (3) scale_nearest_neighbor() allocates based on the first channel's bit depth but iterates all channels, writing 16-bit samples into 8-bit allocations; (4) iden items bypass dimension checks. An attacker can upload or serve a malicious AVIF file to a Next.js application with image optimization enabled. No authentication is required and the attack is network-accessible. Successful exploitation results in arbitrary code execution with the privileges of the Next.js process. Patches are available in Next.js versions 15.5.24 and 16.3.3; AVIF optimization is disabled as a temporary mitigation.
Affected products
- Vercel Next.js >=10.0.0, <15.5.24 or >=16.0.0, <16.3.3
Timeline
- 2026-08-25: disclosed: Vulnerability published in GitHub Advisory Database
- 2026-08-25: patched: Patches released as Next.js 15.5.24 and 16.3.3
- 2026-09-08: advisory: Advisory reviewed and updated in GitHub Advisory Database
References
- https://github.com/strukturag/libheif/security/advisories/GHSA-g89c-p67h-r497
- https://github.com/vercel/next.js/security/advisories/GHSA-2xp9-vwfh-vxw4
- https://github.com/vercel/next.js/pull/97875
- https://github.com/vercel/next.js/pull/97931
- https://github.com/vercel/next.js/commit/3a15b4ac6ac8e70b1a9b18ecc18e8434462899b3
- https://github.com/vercel/next.js/commit/409772ec807def20132d251ad48fd8d8ad4c73c2