fix: remove babel-traverse@6 (CVE-2023-45133) by replacing cross-var - #2690
fix: remove babel-traverse@6 (CVE-2023-45133) by replacing cross-var#2690jainakanksha-msft with Copilot wants to merge 6 commits into
Conversation
|
Done in commit
|
|
@copilot, fix the conflict issues in the PR. |
Merge conflicts resolved in commit
|
|
@copilot, are there any other ways to fix this besides a self-maintained script that may not stay up to date over time? |
There was a problem hiding this comment.
Pull request overview
This PR removes the vulnerable Babel 6 transitive devDependency chain (cross-var → babel-register → babel-core → babel-traverse@6) by replacing cross-var usage with a small in-repo Node.js script, and updates npm scripts/lockfile accordingly to eliminate babel-traverse@6.
Changes:
- Added
scripts/cross-var.jsto perform$VAR_NAMEexpansion usingprocess.envandspawnSync. - Updated
package.jsonscripts to invokenode scripts/cross-var.jsinstead ofcross-var, and removedcross-varfrom devDependencies. - Regenerated
package-lock.jsonto removecross-varand the Babel 6 subtree; also removed a couple of now-redundanttsconfig.jsonoptions and documented the changes inChangeLog.md.
Reviewed changes
Copilot reviewed 3 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tsconfig.json | Removes explicit options that are redundant with the current module/target settings. |
| scripts/cross-var.js | Introduces an in-repo replacement for cross-var to expand $VAR_NAME values before spawning a command. |
| package.json | Drops cross-var dependency and rewrites scripts to use the new Node-based wrapper. |
| package-lock.json | Removes cross-var and its Babel 6 dependency chain from the lockfile. |
| ChangeLog.md | Documents the dependency removal and related config cleanup. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| - Removed `cross-var` devDependency (which pulled in `babel-traverse@6.26.0`, CVE-2023-45133/GHSA-67hx-6x53-jw92) and replaced it with a built-in Node.js script (`scripts/cross-var.js`) providing identical cross-platform variable substitution for Docker build scripts. | ||
| - Removed deprecated `moduleResolution: node` and `downlevelIteration` options from `tsconfig.json` (both were removed in TypeScript 7). |
| arg.replace(/\$([A-Za-z_][A-Za-z0-9_]*)/g, (_, name) => | ||
| Object.prototype.hasOwnProperty.call(process.env, name) | ||
| ? process.env[name] | ||
| : '' | ||
| ) |
Yes. The practical alternatives I see are:
My recommendation would be option 1 ( |
|
@copilot, with option 1, I’m wondering whether the current docker script would run into any issues. |
I don’t expect command length to be the blocker here. These Docker scripts are only ~260–330 characters even if converted to The bigger concern is quoting, not length:
So option 1 is still viable, but I’d treat it as:
If we switched to |
|
@copilot, Ok, then please go ahead with option 1. |
|
@copilot , Ok, then please go ahead with option 1. |
Addressed in Switched the affected npm scripts to
Addressed in Switched the affected npm scripts to |
babel-traverse@6.26.0(CVE-2023-45133, GHSA-67hx-6x53-jw92, critical) was a transitive devDependency viacross-var@1.1.0 → babel-register → babel-core → babel-traverse@6. Babel 6 is EOL with no patched version; the only fix is eliminating the dependency chain.Changes
scripts/cross-var.js— minimal drop-in replacement forcross-varusing only Node.js built-ins (child_process.spawnSync). Substitutes$VAR_NAMEpatterns in arguments fromprocess.env, providing identical cross-platform behavior.package.json— removedcross-varfromdevDependencies; replaced all 18 invocations in npm scripts withnode scripts/cross-var.js.package-lock.json— regenerated;babel-traverseno longer present.Reachability Assessment
Not actively exploitable (high confidence). The vulnerable
path.evaluate()/path.evaluateTruthy()APIs are only triggered by Babel compilation plugins (@babel/plugin-transform-runtime,@babel/preset-env, polyfill providers). This project compiles viatscandesbuild— Babel is never invoked as a compilation pipeline.cross-varonly used Babel to transpile its own internals, never touching user code. Risk is theoretical; fix eliminates the dependency entirely.Original prompt
This section details the Dependabot vulnerability alert you should resolve
<alert_title>Babel vulnerable to arbitrary code execution when compiling specifically crafted malicious code</alert_title>
<alert_description>### Impact
Using Babel to compile code that was specifically crafted by an attacker can lead to arbitrary code execution during compilation, when using plugins that rely on the
path.evaluate()orpath.evaluateTruthy()internal Babel methods.Known affected plugins are:
@babel/plugin-transform-runtime@babel/preset-envwhen using itsuseBuiltInsoption@babel/helper-define-polyfill-provider, such asbabel-plugin-polyfill-corejs3,babel-plugin-polyfill-corejs2,babel-plugin-polyfill-es-shims,babel-plugin-polyfill-regeneratorNo other plugins under the
@babel/namespace are impacted, but third-party plugins might be.Users that only compile trusted code are not impacted.
Patches
The vulnerability has been fixed in
@babel/traverse@7.23.2.Babel 6 does not receive security fixes anymore (see Babel's security policy), hence there is no patch planned for
babel-traverse@6.Workarounds
@babel/traverseto v7.23.2 or higher. You can do this by deleting it from your package manager's lockfile and re-installing the dependencies.@babel/core>=7.23.2 will automatically pull in a non-vulnerable version.@babel/traverseand are using one of the affected packages mentioned above, upgrade them to their latest version to avoid triggering the vulnerable code path in affected@babel/traverseversions:@babel/plugin-transform-runtimev7.23.2@babel/preset-envv7.23.2@babel/helper-define-polyfill-providerv0.4.3babel-plugin-polyfill-corejs2v0.4.6babel-plugin-polyfill-corejs3v0.8.5babel-plugin-polyfill-es-shimsv0.10.0babel-plugin-polyfill-regeneratorv0.5.3</alert_description>critical
https://github.com/babel/babel/security/advisories/GHSA-67hx-6x53-jw92 https://nvd.nist.gov/vuln/detail/CVE-2023-45133 https://github.com/babel/babel/pull/16033 https://github.com/babel/babel/commit/b13376b346946e3f62fc0848c1d2a23223314c82 https://github.com/babel/babel/releases/tag/v7.23.2 https://github.com/babel/babel/releases/tag/v8.0.0-alpha.4 https://www.debian.org/security/2023/dsa-5528 https://lists.debian.org/debian-lts-announce/2023/10/msg00026.html https://babeljs.io/blog/2023/10/16/cve-2023-45133 https://github.com/advisories/GHSA-67hx-6x53-jw92GHSA-67hx-6x53-jw92, CVE-2023-45133
babel-traverse
npm
<vulnerable_versions>6.26.0</vulnerable_versions>
<patched_version></patched_version>
<manifest_path>package-lock.json</manifest_path>
<agent_instructions>please go through the issues mentioned here, identify all issues, and assess whether they can be fixed.
Recommend the necessary changes.
If it is not a breaking change, let's log the issue.
Please verify all test cases and validate the runs.
</agent_instructions>
<task_instructions>Resolve this alert by updating the affected package to a non-vulnerable version. Prefer the lowest non-vulnerable version (see the patched_version field above) over the latest to minimize breaking changes. Include a Reachability Assessment section in the PR description. Review the alert_description field to understand which APIs, features, or configurations are affected, then search the codebase for usage of those specific items. If the vulnerable code path is reachable, explain how (which files, APIs, or call sites use the affected functionality) and note that the codebase is actively exposed to this vulnerability. If the vulnerable code path is not reachable, explain why (e.g. the affected API is never called, the vulnerable configuration is not used) and note that the update is primarily to satisfy vulnerability scanners rather than to address an active risk. If the advisory is too vague to determine reachability (e.g. 'improper input validation' with no specific API named), state that reachability could not be determined and explain why. Include a confidence level in the reachability assessment (e.g. high confidence if the advisory names a specific API and you confirmed it is or is not called, low confidence if the usage is indirect and hard to trace). If no patched version is available, check the alert_description field for a Workarounds section — the advisory may describe configuration changes or usage patterns that mitigate the vulnerability without a version update. If a workaround is available, apply it and leave a code comment referencing the advisory identif...