sharp icon indicating copy to clipboard operation
sharp copied to clipboard

Defective `is.object(null)` Validation Causing Unhandled `TypeError` Crashes

Open codeCraft-Ritik opened this issue 1 month ago • 2 comments

  • 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]) throws TypeError: Cannot read properties of null (reading 'failOn').
  • sharp(img).extend(null) throws TypeError: Cannot read properties of null (reading 'top').
  • sharp(img).convolve(null) throws TypeError: Cannot read properties of null (reading 'kernel').
  • sharp(img).withExif(null) throws TypeError: Cannot convert undefined or null to object.

Recommended Fix

In lib/is.mjs:

const object = (val) => typeof val === 'object' && val !== null;

codeCraft-Ritik avatar Oct 11 '26 04:10 codeCraft-Ritik

This falls under API misuse rather than vulnerability but I agree we should tighten what's accepted.

lovell avatar Oct 11 '26 10:10 lovell

v0.35.6 now available, thanks for reporting.

lovell avatar Nov 28 '26 19:11 lovell