CVE-2026-4800: lodash vulnerable to Code Injection via `_.template` imports key names
Impact The fix for CVE-2021-23337 added validation for the variable option in .template but did not apply the same validation to options.imports key names. Both paths flow into the same Function() constructor sink. When an application passes untrusted input as options.imports key names, an attacker can inject default-parameter expressions that execute arbitrary code at template compilation time.
Published Apr 1, 2026
Affected packages
lodash
- Ecosystem
- npm
- Affected
- >= 4.0.0, <= 4.17.23
- Fixed in
- 4.18.0
- Check
npm ls lodash
lodash-es
- Ecosystem
- npm
- Affected
- >= 4.0.0, <= 4.17.23
- Fixed in
- 4.18.0
- Check
npm ls lodash-es
lodash-amd
- Ecosystem
- npm
- Affected
- >= 4.0.0, <= 4.17.23
- Fixed in
- 4.18.0
- Check
npm ls lodash-amd
lodash.template
- Ecosystem
- npm
- Affected
- >= 4.0.0, < 4.18.0
- Fixed in
- 4.18.0
- Check
npm ls lodash.template
Advisory details
From the GitHub Advisory Database (CC BY 4.0).
Impact
The fix for CVE-2021-23337 added validation for the variable option in _.template but did not apply the same validation to options.imports key names. Both paths flow into the same Function() constructor sink.
When an application passes untrusted input as options.imports key names, an attacker can inject default-parameter expressions that execute arbitrary code at template compilation time.
Additionally, _.template uses assignInWith to merge imports, which enumerates inherited properties via for..in. If Object.prototype has been polluted by any other vector, the polluted keys are copied into the imports object and passed to Function().
Patches
Users should upgrade to version 4.18.0.
The fix applies two changes:
- Validate
importsKeysagainst the existingreForbiddenIdentifierCharsregex (same check already used for thevariableoption) - Replace
assignInWithwithassignWithwhen merging imports, so only own properties are enumerated
Workarounds
Do not pass untrusted input as key names in options.imports. Only use developer-controlled, static key names.
Credited to dolevmiz1, bugbunny-research, M0nd0R, UlisesGascon, falsyvalues, jonchurch, threalwinky, jdalton.
References
- https://github.com/lodash/lodash/security/advisories/GHSA-r5fr-rjxr-66jc
- https://nvd.nist.gov/vuln/detail/CVE-2026-4800
- https://github.com/lodash/lodash/commit/3469357cff396a26c363f8c1b5a91dde28ba4b1c
- https://cna.openjsf.org/security-advisories.html
- https://github.com/advisories/GHSA-35jh-r3h4-6jhm
- https://github.com/advisories/GHSA-r5fr-rjxr-66jc
How this page is made: the data panel comes from the GitHub Advisory Database, CISA’s KEV catalog, the NVD and FIRST EPSS, and updates twice a day. No analysis has been written for this entry yet. Methodology
