Skip to content

fix(mdx-loader): replace image-size with measureImage hook - #12388

Open
kennym wants to merge 2 commits into
facebook:mainfrom
kennym:fix/mdx-loader-measure-image-hook
Open

fix(mdx-loader): replace image-size with measureImage hook#12388
kennym wants to merge 2 commits into
facebook:mainfrom
kennym:fix/mdx-loader-measure-image-hook

Conversation

@kennym

@kennym kennym commented Aug 25, 2026

Copy link
Copy Markdown

Pre-flight checklist

Motivation

@docusaurus/mdx-loader depends on archived image-size@^2.0.2 (CVE-2025-71329 / CVE-2025-71330). There is no published patched release.

#12235 replaced it with image-dimensions only. That drops SVG (unsupported by that library) and has no escape hatch for long-tail formats.

This draft follows the markdown.hooks pattern from #11283:

  • Add optional siteConfig.markdown.hooks.measureImage({ imagePath }).
  • Default: SVG via a small local width/height/viewBox parser; raster via image-dimensions; on failure log and return null (no throw/catch).
  • Remove image-size completely.
  • Document that BMP/ICO/TIFF/PSD/JXL/ICNS are no longer auto-measured unless the site provides a custom hook.

Question for maintainers: is preserving SVG enough for a 3.x fix, or is dropping the long-tail formats v4-only?

Test Plan

  • pnpm exec vitest run packages/docusaurus-mdx-loader/src/remark/transformImage packages/docusaurus/src/server/__tests__/configValidation.test.ts (Node 24)
  • New coverage: SVG attributes, viewBox fallback, measureImage override, config validation
  • Existing transformImage snapshots still emit width/height for PNG fixtures
  • Showcase user.test.ts and admin/scripts/resizeImage.js no longer import image-size

Test links

Deploy preview: https://deploy-preview-12388--docusaurus-2.netlify.app/

Docs: website/docs/api/docusaurus.config.js.mdx (markdown.hooks.measureImage)

Related issues/PRs

image-size is archived and carries unpatched DoS CVEs. Measure SVG
locally and raster formats via image-dimensions, with an optional
markdown.hooks.measureImage escape hatch.
@meta-cla

meta-cla Bot commented Aug 25, 2026

Copy link
Copy Markdown

Hi @kennym!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@socket-security

socket-security Bot commented Aug 25, 2026

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addedimage-dimensions@​2.5.110010010084100

View full report

@netlify

netlify Bot commented Aug 25, 2026

Copy link
Copy Markdown

[V2]

Built without sensitive environment variables

Name Link
🔨 Latest commit 6f97dc4
🔍 Latest deploy log https://app.netlify.com/projects/docusaurus-2/deploys/6a8d9963acc50100086baaa6
😎 Deploy Preview https://deploy-preview-12388--docusaurus-2.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@meta-cla

meta-cla Bot commented Aug 25, 2026

Copy link
Copy Markdown

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@meta-cla meta-cla Bot added the CLA Signed Signed Facebook CLA label Aug 25, 2026
@kennym
kennym marked this pull request as ready for review August 25, 2026 13:56
@kennym

kennym commented Aug 26, 2026

Copy link
Copy Markdown
Author

@slorber @Josh-Cena any feedback here?

@jeffersonlicet

Copy link
Copy Markdown
Contributor

+1

@kennym

kennym commented Aug 31, 2026

Copy link
Copy Markdown
Author

@slorber @Josh-Cena sorry for following up again, but what is the hold up?

It's been 5 business days without a word.

We have a security SLA and this issue currently drags it down.

@kennym

kennym commented Sep 3, 2026

Copy link
Copy Markdown
Author

bump

mihail-alexe-nutanix added a commit to vite-styleguidist/vite-styleguidist that referenced this pull request Sep 6, 2026
…urity PRs

The two remaining Dependabot alerts are both image-size 2.0.2, pulled in by
@docusaurus/mdx-loader. Neither has a patched version and neither ever will:
2.0.2 is the last release (April 2025) and the upstream repository was archived
in June 2026, a week before the advisories were published. The Docusaurus pull
request that replaces the dependency (facebook/docusaurus#12388) is still open,
and the only alternative on npm is a one-month-old fork with a single unknown
maintainer, which is a worse trade for code that runs in CI.

So the honest fix is a written mitigation rather than a version bump. site's
Readme now records where image-size runs (mdx-loader's transformImage remark
plugin, at build time only), why the two infinite-loop bugs are unreachable
here (the only images measured are the PNG/JPEG/SVG files committed to this
repository, and none of ICNS, JXL or HEIF is among them), what the worst case
actually is (a hung `npm run build`, triggered by someone who can already push
to the repository) and the three changes that would make it exploitable.

Dependabot: the site entry now also groups security updates. `groups` applies
to version updates only unless `applies-to: security-updates` is set, which is
why a single Docusaurus advisory chain arrived as five separate pull requests.
Nothing in site/ is published to npm, so one grouped PR is the right unit of
review for it. The root, examples and github-actions entries are untouched.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@kennym

kennym commented Sep 7, 2026

Copy link
Copy Markdown
Author

@slorber @Josh-Cena friendly bump

@slorber

slorber commented Sep 7, 2026

Copy link
Copy Markdown
Collaborator

It's been 5 business days without a word.

I'm sorry but this is how OSS works 🤷‍♂️

We have a security SLA and this issue currently drags it down.

Even if I merged this today, this is not really the plan for release in v3.x as a patch release.

The image-size vulnerabilities are only theoretical DoS vulnerabilities, not really impactful. You can safely ignore them.

We don't particularly want to release a breaking change in v3 for a vulnerability that is reported by broken security tooling (https://overreacted.io/npm-audit-broken-by-design/) and that nobody encounters in practice.


If you really care about a fix for a theoretical thing, it remains possible to ship it on your own and make it available for the community:

  • Create a package that uses the exact same api as image-size (we only use ìmport {imageSizeFromFile} from 'image-size/fromFile') but uses image-dimension` under the hood
  • Publish it to npm so that others can leverage it if they want
  • Make your bundle resolve your package instead of image-size (alias with "image-size": "npm:my-wrapper-package")

Edit: an alternative to alias already exists. Not vetted; use this carefully. The maintainer has only ever published this package, so you must be cautious and check what's actually distributed (not just on GitHub, the actual code that runs)

https://github.com/lcf2212dev/image-size-next

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

Labels

CLA Signed Signed Facebook CLA

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Replace unmaintained dependency image-size with active CVEs (CVSS 7.5)

3 participants