Skip to content

fix(dts-plugin): do not overwrite on extract when the types folder was just deleted - #5025

Open
taufiq-dev wants to merge 2 commits into
module-federation:mainfrom
taufiq-dev:fix/dts-plugin-extract-overwrite
Open

fix(dts-plugin): do not overwrite on extract when the types folder was just deleted#5025
taufiq-dev wants to merge 2 commits into
module-federation:mainfrom
taufiq-dev:fix/dts-plugin-extract-overwrite

Conversation

@taufiq-dev

@taufiq-dev taufiq-dev commented Sep 3, 2026

Copy link
Copy Markdown

Description

downloadTypesArchive removes the types destination folder right before extracting the remote's @mf-types.zip when deleteTypesFolder is enabled (the default), then calls zip.extractAllTo(destinationPath, true). In that path every entry is new, so overwrite: true was redundant.

adm-zip 0.5.9 through 0.6.0 (the version dts-plugin pins) is affected by CVE-2026-76845, symlink following at the extraction destination. Per the CVE text, the write is only reachable when overwrite is enabled, because adm-zip's existsSync check otherwise declines. This PR passes overwrite only when something may already exist at the destination, tracked by whether the rm actually succeeded (typesFolderRemoved):

  • Default path (deleteTypesFolder: true, rm succeeded): overwrite is off, the CVE precondition is no longer met, and the written output is unchanged since every entry is new.
  • deleteTypesFolder: false: overwrite stays on, so users who keep an existing folder still get refreshed types, exactly as before.
  • deleteTypesFolder: true but rm failed (already caught and logged): overwrite stays on, exactly as before, so consumers never get silently stale types. (Updated after review feedback; the first revision tied overwrite to the option alone.)

This is a mitigation of the reachable path in this package, not a fix of adm-zip. A fixed adm-zip release (cthackers/adm-zip#575 is open upstream) plus a bump is still the complete fix.

Not in this PR: packages/native-federation-typescript and packages/native-federation-tests have the same rm then extractAllTo(destinationPath, true) sequence in their archiveHandler.ts and also depend on adm-zip ^0.6.0. Happy to apply the same change there in this PR or a follow-up if maintainers want it.

Related Issue

Fixes #5024

Types of changes

  • Docs change / refactoring / dependency upgrade
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

Checklist

  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • I have updated the documentation.

No test added: the change is a single argument on the default path with identical output, and there is no existing test asserting the extractAllTo arguments. I can add one if you would like it pinned. Changeset included (@module-federation/dts-plugin patch).

…s just deleted

adm-zip 0.5.9 through 0.6.0 (CVE-2026-76845) follows symlinks at the
extraction destination, but only when overwrite is enabled.
downloadTypesArchive removes the destination folder right before
extracting when deleteTypesFolder is true (the default), so passing
overwrite: true there was redundant. Tie overwrite to
!deleteTypesFolder so the default path no longer meets the CVE's
precondition, while users who keep an existing folder still get
refreshed types.

Fixes module-federation#5024
@changeset-bot

changeset-bot Bot commented Sep 3, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 5d424ba

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 48 packages
Name Type
@module-federation/dts-plugin Patch
@module-federation/cli Patch
@module-federation/enhanced Patch
@module-federation/manifest Patch
@module-federation/metro Patch
@module-federation/rspack Patch
@module-federation/modern-js-v3 Patch
@module-federation/modern-js Patch
@module-federation/nextjs-mf Patch
@module-federation/node Patch
@module-federation/rsbuild-plugin Patch
@module-federation/rspress-plugin Patch
@module-federation/rstest Patch
@module-federation/storybook-addon Patch
shared-tree-shaking-no-server-host Patch
shared-tree-shaking-no-server-provider Patch
@module-federation/metro-plugin-rnc-cli Patch
@module-federation/metro-plugin-rnef Patch
@module-federation/metro-plugin-rock Patch
shared-tree-shaking-with-server-host Patch
shared-tree-shaking-with-server-provider Patch
node-dynamic-remote-new-version Patch
node-dynamic-remote Patch
@module-federation/playground Patch
remote5 Patch
remote6 Patch
website-new Patch
@module-federation/devtools Patch
create-module-federation Patch
@module-federation/error-codes Patch
@module-federation/managers Patch
@module-federation/retry-plugin Patch
@module-federation/runtime-core Patch
@module-federation/runtime-tools Patch
@module-federation/runtime Patch
@module-federation/sdk Patch
@module-federation/third-party-dts-extractor Patch
@module-federation/treeshake-frontend Patch
@module-federation/treeshake-server Patch
@module-federation/webpack-bundler-runtime Patch
@module-federation/bridge-react-webpack-plugin Patch
@module-federation/bridge-react Patch
@module-federation/bridge-shared Patch
@module-federation/bridge-vue3 Patch
@module-federation/inject-external-runtime-core-plugin Patch
@module-federation/esbuild Patch
@module-federation/observability-plugin Patch
@module-federation/utilities Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ac3e066b2f

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

// and overwrite is redundant. Keeping it off removes the precondition of
// CVE-2026-76845 (adm-zip follows symlinks at the destination only when
// overwrite is enabled).
zip.extractAllTo(destinationPath, !hostOptions.deleteTypesFolder);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Abort extraction when the destination cleanup fails

When deleteTypesFolder is true but rm rejects while leaving the destination usable—for example, an unrelated locked child prevents removal on Windows—this passes overwrite: false, so adm-zip silently skips every archive entry whose path already exists and the function still logs and returns success. Previously those matching declarations were refreshed despite the cleanup failure; now consumers can unknowingly compile against stale types. Propagate the removal failure into the retry/error path rather than extracting under the assumption that the folder was deleted.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Good catch, agreed that silently stale types is worse than the previous behaviour. Fixed in e93da36: overwrite is now tied to whether the rm actually succeeded (typesFolderRemoved), not to the option alone. So the default happy path extracts with overwrite: false, while deleteTypesFolder: false and a failed cleanup both keep overwrite: true exactly as before. I chose that over aborting on cleanup failure because the previous behaviour on that path was to refresh what it could and succeed, and changing that felt out of scope for a CVE mitigation.

Review feedback: with overwrite tied to deleteTypesFolder alone, a failed
rm that leaves the folder usable would make adm-zip silently skip existing
entries and still report success, so consumers could compile against stale
types. Track whether the removal actually succeeded and only disable
overwrite in that case; the failure path keeps the previous behaviour.
@taufiq-dev
taufiq-dev force-pushed the fix/dts-plugin-extract-overwrite branch from e93da36 to 5d424ba Compare September 3, 2026 05:20
@taufiq-dev

Copy link
Copy Markdown
Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: 5d424ba7ef

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

dts-plugin: adm-zip@0.6.0 is affected by CVE-2026-76845 and downloadTypesArchive meets its overwrite precondition

1 participant