CVE-2025-27789: Babel has inefficient RexExp complexity in generated code with .replace when transpiling named capturing groups
(updated )
When using Babel to compile regular expression named capturing groups, Babel will generate a polyfill for the .replace
method that has quadratic complexity on some specific replacement pattern strings (i.e. the second argument passed to .replace
).
Your generated code is vulnerable if all the following conditions are true:
- You use Babel to compile regular expression named capturing groups
- You use the
.replace
method on a regular expression that contains named capturing groups - Your code uses untrusted strings as the second argument of
.replace
If you are using @babel/preset-env
with the targets
option, the transform that injects the vulnerable code is automatically enabled if:
- you use duplicated named capturing groups, and target any browser older than Chrome/Edge 126, Opera 112, Firefox 129, Safari 17.4, or Node.js 23
- you use any named capturing groups, and target any browser older than Chrome 64, Opera 71, Edge 79, Firefox 78, Safari 11.1, or Node.js 10
You can verify what transforms @babel/preset-env
is using by enabling the debug
option.
References
Detect and mitigate CVE-2025-27789 with GitLab Dependency Scanning
Secure your software supply chain by verifying that all open source dependencies used in your projects contain no disclosed vulnerabilities. Learn more about Dependency Scanning →