sharp
sharp copied to clipboard
Defective `is.object(null)` Validation Causing Unhandled `TypeError` Crashes
- Severity: Medium/High (Validation Bypass & Unhandled Exception)
- Target Files:
lib/is.mjs- Affecting
lib/composite.mjs,lib/resize.mjs,lib/operation.mjs,lib/output.mjs
Description & Root Cause
In lib/is.mjs, line 16 defines:
const object = (val) => typeof val === 'object';
In JavaScript, typeof null === 'object'. Because is.object(null) evaluates to true, passing null where an object is expected slips past validation guards and throws uncaught internal property-read TypeError exceptions instead of the structured invalidParameterError:
sharp(img).composite([null])throwsTypeError: Cannot read properties of null (reading 'failOn').sharp(img).extend(null)throwsTypeError: Cannot read properties of null (reading 'top').sharp(img).convolve(null)throwsTypeError: Cannot read properties of null (reading 'kernel').sharp(img).withExif(null)throwsTypeError: Cannot convert undefined or null to object.
Recommended Fix
In lib/is.mjs:
const object = (val) => typeof val === 'object' && val !== null;
This falls under API misuse rather than vulnerability but I agree we should tighten what's accepted.
v0.35.6 now available, thanks for reporting.