Skip to content

fix(storage-resize-images): bump sharp to ^0.35.5 and restrict libvips loaders to supported formats - #3247

Open
cybrdude wants to merge 4 commits into
firebase:nextfrom
cybrdude:resize-images-sharp-0.35.5
Open

cybrdude wants to merge 4 commits into
firebase:nextfrom
cybrdude:resize-images-sharp-0.35.5

Conversation

@cybrdude

@cybrdude cybrdude commented Oct 16, 2026 •

Copy link
Copy Markdown

Fixes #3246

shouldResize() admits an object by its contentType, which is metadata the uploader sets, while libvips selects the loader from the file bytes. An SVG uploaded as image/png therefore reaches librsvg, a format this extension does not list as supported. The published 0.3.6 bundle (sharp 0.34.5: libvips 8.17.3, libheif 1.20.2, librsvg 2.61.2) is behind three sharp advisories: GHSA-f88m-g3jw-g9cj (< 0.35.0, GIF and TIFF loaders), GHSA-rgj7-g3m4-5g8c (< 0.35.4, libheif, AVIF) and GHSA-wq5f-xc86-pv6w (< 0.35.5, librsvg, SVG). next at 0.35.3 still carries the last two.

This PR:

  • moves sharp to ^0.35.5 (libvips 8.18.7, libheif 1.23.5, librsvg 2.63.2 in the prebuilt binaries); the lockfile diff is sharp, its @img/* platform packages and @emnapi/runtime;
  • adds src/loaders.ts: block the VipsForeignLoad base class at module load and re-enable only the loaders for supportedContentTypes (VipsForeignLoadJpeg, VipsForeignLoadPng, VipsForeignLoadTiff, VipsForeignLoadWebp, VipsForeignLoadNsgif, VipsForeignLoadHeif), called once from resize-image.ts;
  • adds __tests__/loaders.test.ts: the contentType gate alone admits SVG bytes labelled image/png; resize() now rejects them with "unsupported image format"; jpeg, png, tiff, webp, gif and avif still resize. The second test fails on the current code.
  • CHANGELOG entry and version 0.3.7.

Tests: jest __tests__/loaders.test.ts __tests__/resize.test.ts __tests__/convert-image.test.ts __tests__/filters.test.ts __tests__/util.test.ts -> 30 passed. __tests__/unit/* fail identically before and after (they expect config env the suite does not set).

Reported through the channels in SECURITY.md as well (Google VRP b/574386863, advisory GHSA-pvx3-hg35-5vwm); this PR is the fix side.

… bump

Part 1 of 4 of the sharp ^0.35.5 bump and libvips loader allowlist (CHANGELOG entry, extension.yaml 0.3.7). Functions code, lockfile and tests follow in the next commits on this branch.
Part 2 of 4: package.json sharp ^0.35.5 and the matching lockfile (sharp 0.35.5, @img/* 0.35.5 and sharp-libvips 1.3.4, @emnapi/runtime 1.11.3; no other entries change). Brings libvips 8.18.7, libheif 1.23.5 and librsvg 2.63.2 (GHSA-f88m-g3jw-g9cj, GHSA-rgj7-g3m4-5g8c, GHSA-wq5f-xc86-pv6w).
… formats

Part 3 of 4: src/loaders.ts blocks the VipsForeignLoad base class at module load and re-enables only VipsForeignLoadJpeg, Png, Tiff, Webp, Nsgif and Heif, the loaders for supportedContentTypes. resize-image.ts calls restrictLoaders() once. shouldResize() reads the uploader-set contentType while libvips picks the loader from the bytes, so without this an SVG or any other decodable file uploaded under a supported contentType still reached the loader for its real format.
@cybrdude
cybrdude requested a review from a team as a code owner October 16, 2026 17:32

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request bumps the sharp dependency to version 0.35.5 and introduces a mechanism to restrict libvips loaders to only the supported image formats (JPEG, PNG, TIFF, WebP, GIF, and HEIF). This restriction prevents files of unsupported formats (such as SVG or PDF) from being decoded even if they are uploaded with a spoofed, supported content-type metadata. Tests and a test asset have been added to verify this behavior. There are no review comments, and I have no feedback to provide.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant