libheif: GHSA-g89c-p67h-r497 and GHSA-2jg2-4ch7-h545 has a security flaw
Sharp is a popular Node.js image-processing package. Security flaws in libheif, the code it bundles to open HEIC, HEIF, and AVIF photos, can let a booby-trapped image file run an attacker's own code on the server that processes it.
- Severity
- Not scoredNo CVSS score recorded
- Fix
- Fixed in 0.35.4Fix recorded 3 days ago
- Affected versions
- before 0.35.4
- Affects
- sharp
How it works
- The bug lives in libheif, the image decoder sharp bundles for HEIC/HEIF/AVIF files. libheif lets one image item reference another and attach its own transparency (alpha) layer, but never checks that two alpha layers on the same image actually match in size or bit depth.
- A crafted image can make libheif register a normal 8 bit alpha layer and then a second, higher precision alpha layer on top of it.
- When libheif resizes these layers it allocates memory sized for the first 8 bit layer, then writes the second layer's larger values into that same space, overflowing it.
- This happens automatically the moment a program decodes the image, without any special settings.
What to do
Run npm list sharp in your project to see the installed version and compare it against 0.35.4. If your code passes HEIC, HEIF, or AVIF files that came from users, uploads, or external sites into sharp, and the version is older than 0.35.4, treat it as exposed. If you also have a system wide libheif installed outside of sharp's own binary, check that it is 1.23.2 or newer.
Run this in the application environment you want to check:
npm list sharpUpgrade sharp to 0.35.4 or later with npm install sharp@latest, which bundles the fixed libheif 1.23.2. If you cannot upgrade immediately, add sharp.block({ operation: ["VipsForeignLoadHeif"] }) to your code so sharp refuses to decode AVIF/HEIC images until you can patch. If you rely on a separately installed system libheif, update that package to 1.23.2 through your OS package manager.
Technical details
sharp: Vulnerabilities in libheif: GHSA-g89c-p67h-r497 and GHSA-2jg2-4ch7-h545. A number of vulnerabilities, two rated as "Critical" severity using CVSSv3, have been discovered and fixed in the upstream libheif dependency.
References
- github.com · v0.35.4 (tag) vendor advisory patch release notes
- github.com · GHSA-rgj7-g3m4-5g8c vendor advisory
- github.com · GHSA-2jg2-4ch7-h545 vendor advisory
- github.com · GHSA-g89c-p67h-r497 vendor advisory
- osv.dev · GHSA-RGJ7-G3M4-5G8C vdb entry