Skip to content

fix: patch lerna's tar interop bug, fixing GHSA-r292-9mhp-454m - #9546

Closed
manojkumar138 wants to merge 1 commit into
masterfrom
manojkumar138/revert-tar-bump-exclude-ghsa-r292
Closed

fix: patch lerna's tar interop bug, fixing GHSA-r292-9mhp-454m#9546
manojkumar138 wants to merge 1 commit into
masterfrom
manojkumar138/revert-tar-bump-exclude-ghsa-r292

Conversation

@manojkumar138

@manojkumar138 manojkumar138 commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Summary

PR #9542 bumped tar to 7.5.21 to fix GHSA-r292-9mhp-454m (CVSS 7.5 stack-overflow DoS), claiming it was verified safe for lerna's packDirectory usage. That verification was incomplete, and the bump broke the real publish pipeline once merged:

lerna ERR! TypeError: Cannot read properties of undefined (reading 'create')
    at packDirectory (node_modules/lerna/dist/index.js:6429:39)

(failing run)

Root cause: lerna's bundled code does esbuild's __toESM(require('tar')) interop wrapper, then calls .default.create()/.default.list(). tar 7.5.21's CJS build sets __esModule: true but has no actual .default export (only named exports like create/list). esbuild's __toESM only synthesizes a .default fallback when !mod.__esModule — since tar 7.5.21 sets that flag, __toESM leaves .default unset, so it's undefined at runtime. I reproduced lerna's exact __toESM logic in isolation to confirm this precisely, rather than just re-testing bump-and-hope like last time.

Fix: instead of excluding the CVE (which was my first fallback plan — see comment history), this patches the actual bug via patch-package. Both call sites in lerna's dist/index.js become (import_tar.default || import_tar).list(...) and (import_tar2.default || import_tar2).create(...), falling back to the raw module when .default isn't populated. Verified against a byte-for-byte reproduction of lerna's __toESM helper that .default is undefined before the patch and that both .list/.create resolve correctly after it.

This lets us actually take the tar 7.5.21 security fix rather than suppressing the finding.

Ticket

CECHO-1941 (used per request for commit/branch tracking; unrelated to the actual token-onboarding content of that ticket — this is a CI/dependency fix)

Test plan

  • patch-package applies cleanly on fresh yarn install
  • Reproduced lerna's exact __toESM interop logic standalone — confirmed bug before patch, confirmed fix after
  • CI passes
  • Release workflow's "Enforce Vulnerability Severity Threshold" and "Lerna Publish" steps both pass on next publish run

@manojkumar138
manojkumar138 requested review from a team as code owners August 24, 2026 12:13
@manojkumar138
manojkumar138 marked this pull request as draft August 24, 2026 12:14
CECHO-1941 PR #9542 bumped tar to 7.5.21 to fix GHSA-r292-9mhp-454m
(CVSS 7.5 stack-overflow DoS), claiming it was verified safe for
lerna's packDirectory usage. That verification was incomplete and
the bump broke the real publish pipeline once merged:

  lerna ERR! TypeError: Cannot read properties of undefined
  (reading 'create')
    at packDirectory (node_modules/lerna/dist/index.js:6429:39)

Root cause: lerna's bundled code does esbuild's
__toESM(require('tar')) interop wrapper, then calls .default.create()
/.default.list(). tar 7.5.21's CJS build sets __esModule: true but
has no actual .default export (only named exports like create/list).
esbuild's __toESM only synthesizes a .default fallback when
!mod.__esModule -- since tar 7.5.21 sets that flag, __toESM leaves
.default unset, so it's undefined at runtime. Reproduced lerna's
exact __toESM logic in isolation to confirm this precisely, rather
than just re-testing bump-and-hope.

Instead of excluding the CVE, this patches the actual bug via
patch-package: both call sites in lerna's dist/index.js become
(import_tar.default || import_tar).list(...) and
(import_tar2.default || import_tar2).create(...), falling back to
the raw module when .default isn't populated. Verified against a
byte-for-byte reproduction of lerna's __toESM helper that .default
is undefined before the patch and that both .list/.create resolve
correctly after it.

Ticket: CECHO-1941
@manojkumar138
manojkumar138 force-pushed the manojkumar138/revert-tar-bump-exclude-ghsa-r292 branch from 8b4653e to 9ef5e95 Compare August 24, 2026 13:25
@manojkumar138 manojkumar138 changed the title fix: revert tar 7.5.21 bump, exclude GHSA-r292-9mhp-454m instead fix: patch lerna's tar interop bug, fixing GHSA-r292-9mhp-454m Aug 24, 2026
@manojkumar138
manojkumar138 marked this pull request as ready for review August 25, 2026 04:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant