CVE-2021-23337: Lodash Command Injection Vulnerability

HIGH
Advisory Identifier: GHSA-35jh-r3h4-6jhm
CVSS 7.2
CWE-94 CWE-77
Published
Advisory Summary

CVE-2021-23337 is a HIGH (CVSS 7.2) command injection vulnerability (CWE-94: Improper Control of Generation of Code ('Code Injection')) affecting Lodash libraries in the npm ecosystem. The issue involves command injection in lodash. Remediation is available by upgrading affected packages to version 4.17.21.

CVE-2021-23337 at a Glance

CVE Identifier CVE-2021-23337
GHSA Identifier GHSA-35jh-r3h4-6jhm
Severity HIGH
CVSS v3.1 Base Score 7.2
CWE Classification CWE-94: Improper Control of Generation of Code ('Code Injection')
Affected Product Lodash
Package Ecosystem npm
Published Date
Last Updated

Security Impact

CVSS: 7.2

The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:L/PR:H/UI:N/S:U/C:H/I:H/A:H).

Attack Vector Network (AV:N)
Attack Complexity Low (AC:L)
Privileges Required High (PR:H)
User Interaction None (UI:N)
Scope Unchanged (S:U)
Confidentiality High (C:H)
Integrity High (I:H)
Availability High (A:H)

How to Fix CVE-2021-23337

To remediate this vulnerability, upgrade all affected Lodash dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

lodash fixed: 4.17.21
npm install lodash@4.17.21
lodash-es fixed: 4.17.21
npm install lodash-es@4.17.21
lodash.template fixed: Latest secure release
npm install lodash.template@Latest secure release
lodash-template fixed: Latest secure release
npm install lodash-template@Latest secure release
lodash-rails fixed: 4.17.21
Upgrade lodash-rails to 4.17.21
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

npm ls lodash

How to Check if You Are Affected

To determine whether your Node.js application is affected by CVE-2021-23337, inspect your project dependencies using npm:

npm ls lodash

Analyze the terminal output to locate any version of Lodash in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 4.17.21), your application is affected.

Note: The npm ls lodash command inspects dependencies declared in your package.json and lockfile; it does not perform automated runtime dynamic scanning.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-94: Improper Control of Generation of Code ('Code Injection'), where the product constructs all or part of a code segment using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the syntax or behavior of the intended code segment. In Lodash, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

`lodash` versions prior to 4.17.21 are vulnerable to Command Injection via the template function.

CVE-2021-23337 Affected Lodash Versions

5 component(s)
Fixed Versions:
4.17.21
Product / Package Ecosystem Affected Versions Fixed Version
lodash
npm
< 4.17.21
4.17.21
lodash-es
npm
< 4.17.21
4.17.21
lodash.template
npm
≤ 4.5.0
lodash-template
npm
≤ 1.0.0
lodash-rails
RubyGems
< 4.17.21
4.17.21

References

NVD — CVE-2021-23337 NVD
https://nvd.nist.gov/vuln/detail/CVE-2021-23337
Security Fix Commit FIX COMMIT
https://github.com/lodash/lodash/commit/3469357cff396a26c363f8c1b5a91dde28ba4b1c
Lodash Security Information SECURITY
https://www.oracle.com/security-alerts/cpuoct2021.html
Lodash Security Information SECURITY
https://www.oracle.com/security-alerts/cpujul2022.html
Lodash Security Information SECURITY
https://www.oracle.com/security-alerts/cpujan2022.html
Lodash Security Information SECURITY
https://www.oracle.com//security-alerts/cpujul2021.html
snyk.io/vuln/snyk-js-lodash... WEB
https://snyk.io/vuln/SNYK-JS-LODASH-1040724
snyk.io/vuln/snyk-java-orgw... WEB
https://snyk.io/vuln/SNYK-JAVA-ORGWEBJARSNPM-1074929
snyk.io/vuln/snyk-java-orgw... WEB
https://snyk.io/vuln/SNYK-JAVA-ORGWEBJARSBOWERGITHUBLODASH-1074931
snyk.io/vuln/snyk-java-orgw... WEB
https://snyk.io/vuln/SNYK-JAVA-ORGWEBJARSBOWER-1074928
snyk.io/vuln/snyk-java-orgw... WEB
https://snyk.io/vuln/SNYK-JAVA-ORGWEBJARS-1074930
snyk.io/vuln/snyk-java-orgf... WEB
https://snyk.io/vuln/SNYK-JAVA-ORGFUJIONWEBJARS-1074932
Lodash Security Information SECURITY
https://security.netapp.com/advisory/ntap-20210312-0006
Lodash Source Repository REPOSITORY
https://github.com/rubysec/ruby-advisory-db/blob/master/gems/lodash-rails/CVE-2021-23337.yml
Lodash Source Repository REPOSITORY
https://github.com/lodash/lodash/blob/ddfd9b11a0126db2302cb70ec9973b66baec0975/lodash.js#L14851
Lodash Source Repository REPOSITORY
https://github.com/lodash/lodash
cert-portal.siemens.com/productcert/pdf/ssa... WEB
https://cert-portal.siemens.com/productcert/pdf/ssa-637483.pdf

Frequently Asked Questions

What is CVE-2021-23337?
CVE-2021-23337 is a security vulnerability in Lodash involving Command Injection in lodash under CWE-94: Improper Control of Generation of Code ('Code Injection').
Which Lodash versions are affected?
Affected versions include releases prior to 4.17.21 across affected packages: lodash, lodash-es, lodash.template, lodash-template, lodash-rails.
What version fixes CVE-2021-23337?
Upgrading to 4.17.21 (or the latest patched release for your respective branch) resolves the vulnerability.
Is lodash affected?
Yes, lodash is affected in releases prior to 4.17.21. Upgrade your dependency to 4.17.21 or later.
Is lodash-es affected?
Yes, lodash-es is affected in releases prior to 4.17.21. Upgrade your dependency to 4.17.21 or later.
What is the CVSS score of CVE-2021-23337?
CVE-2021-23337 has a CVSS v3.1 base score of 7.2 (HIGH) with vector string CVSS:3.1/AV:N/AC:L/PR:H/UI:N/S:U/C:H/I:H/A:H.
What CWE is associated with CVE-2021-23337?
CVE-2021-23337 is classified under CWE-94: Improper Control of Generation of Code ('Code Injection') (The product constructs all or part of a code segment using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the syntax or behavior of the intended code segment.).
How can I check npm dependencies for CVE-2021-23337?
Run the dependency tree command: 'npm ls lodash'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-35jh-r3h4-6jhm",
  "modified" : "2025-08-12T21:44:24Z",
  "published" : "2021-05-06T16:05:51Z",
  "aliases" : [ "CVE-2021-23337" ],
  "summary" : "Command Injection in lodash",
  "details" : "`lodash` versions prior to 4.17.21 are vulnerable to Command Injection via the template function.",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:H/UI:N/S:U/C:H/I:H/A:H"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "npm",
      "name" : "lodash"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "4.17.21"
      } ]
    } ]
  }, {
    "package" : {
      "ecosystem" : "npm",
      "name" : "lodash-es"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "4.17.21"
      } ]
    } ]
  }, {
    "package" : {
      "ecosystem" : "npm",
      "name" : "lodash.template"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "last_affected" : "4.5.0"
      } ]
    } ]
  }, {
    "package" : {
      "ecosystem" : "npm",
      "name" : "lodash-template"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "last_affected" : "1.0.0"
      } ]
    } ]
  }, {
    "package" : {
      "ecosystem" : "RubyGems",
      "name" : "lodash-rails"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "4.17.21"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2021-23337"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/lodash/lodash/commit/3469357cff396a26c363f8c1b5a91dde28ba4b1c"
  }, {
    "type" : "WEB",
    "url" : "https://www.oracle.com/security-alerts/cpuoct2021.html"
  }, {
    "type" : "WEB",
    "url" : "https://www.oracle.com/security-alerts/cpujul2022.html"
  }, {
    "type" : "WEB",
    "url" : "https://www.oracle.com/security-alerts/cpujan2022.html"
  }, {
    "type" : "WEB",
    "url" : "https://www.oracle.com//security-alerts/cpujul2021.html"
  }, {
    "type" : "WEB",
    "url" : "https://snyk.io/vuln/SNYK-JS-LODASH-1040724"
  }, {
    "type" : "WEB",
    "url" : "https://snyk.io/vuln/SNYK-JAVA-ORGWEBJARSNPM-1074929"
  }, {
    "type" : "WEB",
    "url" : "https://snyk.io/vuln/SNYK-JAVA-ORGWEBJARSBOWERGITHUBLODASH-1074931"
  }, {
    "type" : "WEB",
    "url" : "https://snyk.io/vuln/SNYK-JAVA-ORGWEBJARSBOWER-1074928"
  }, {
    "type" : "WEB",
    "url" : "https://snyk.io/vuln/SNYK-JAVA-ORGWEBJARS-1074930"
  }, {
    "type" : "WEB",
    "url" : "https://snyk.io/vuln/SNYK-JAVA-ORGFUJIONWEBJARS-1074932"
  }, {
    "type" : "WEB",
    "url" : "https://security.netapp.com/advisory/ntap-20210312-0006"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/rubysec/ruby-advisory-db/blob/master/gems/lodash-rails/CVE-2021-23337.yml"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/lodash/lodash/blob/ddfd9b11a0126db2302cb70ec9973b66baec0975/lodash.js#L14851"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/lodash/lodash"
  }, {
    "type" : "WEB",
    "url" : "https://cert-portal.siemens.com/productcert/pdf/ssa-637483.pdf"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-77", "CWE-94" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2021-03-31T23:59:26Z",
    "nvd_published_at" : "2021-02-15T13:15:00Z"
  }
}