High

lodash vulnerable to Code Injection via `_.template` imports key names

  • Disclosed: 06.05.2021
  • Updated: 17.10.2026 05:17

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:

  1. Validate importsKeys against the existing reForbiddenIdentifierChars regex (same check already used for the variable option)
  2. Replace assignInWith with assignWith when 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.

Affected software

Click a technology to see all vulnerabilities affecting it.

PlatformPackageVulnerable versionsFixed in
npm package lodash >= 4.0.0, < 4.18.0 4.18.0
npm package lodash-amd >= 4.0.0, < 4.18.0 4.18.0
npm package lodash-es >= 4.0.0, < 4.18.0 4.18.0
npm package lodash-template <= 1.0.0 no fix
npm package lodash.template >= 4.0.0, < 4.18.0 4.18.0

References

CVSS score 8.1/10
CVSS vector
CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:H/A:H
Weakness (CWE)
CWE-77, CWE-94
Platform
npm
Package
lodash, lodash-amd, lodash-es
Disclosed
06.05.2021
Updated
17.10.2026 05:17

Sources and licenses

OSV / GitHub Advisory Database - GHSA-35jh-r3h4-6jhm - CC BY 4.0

OSV / GitHub Advisory Database - GHSA-r5fr-rjxr-66jc - CC BY 4.0

Vulnerability history: lodash-amd

All published vulnerabilities of this package (npm package), newest first. Shows whether this is a one-off slip or a package that needs watching.

Total entries
4
First → latest
07.2019 01.2026
Without a fix
0
Exploited in attacks
0

Severity breakdown

  • Critical 1
  • High 1
  • Medium 2

Disclosures per year

  1. 2019: 2
  2. 2020: 0
  3. 2021: 1
  4. 2022: 0
  5. 2023: 0
  6. 2024: 0
  7. 2025: 0
  8. 2026: 1
  1. lodash vulnerable to Code Injection via `_.template` imports key names this entry
    High · 8.1 CVE-2021-23337 >= 4.0.0, < 4.18.0 4.18.0
  2. Medium · 6.5 CVE-2019-1010266 >= 4.7.0, < 4.17.11 4.17.11
  3. Critical · 9.1 CVE-2019-10744 < 4.17.13 4.17.13

Know which vulnerabilities affect your application

With the DockRay integration and software inventory enabled, DockRay checks reported component versions against known vulnerabilities and notifies you about confirmed matches. Coverage depends on the supported technology and available advisory data.

Connect your application
DockRay newsletter

Application security in your inbox

Important vulnerabilities, actionable guidance and practical advice for your applications. Choose your technologies and follow what matters to your project.

  • A daily digest of new vulnerabilities, critical ones included.
  • Notifications about important updates.
  • Practical advice on application security and monitoring.

Leave empty to receive updates for every technology.

Free to subscribe. Unsubscribe with one click in any email.