CVE-2021-42740: Shell quote Improper Neutralization Of Special Elements Vulnerability
CRITICALCVE-2021-42740 is a CRITICAL (CVSS 9.8) improper neutralization of special elements vulnerability (CWE-77: Improper Neutralization of Special Elements used in a Command ('Command Injection')) affecting Shell quote libraries in the npm ecosystem. The issue involves improper neutralization of special elements used in a command in shell-quote. Remediation is available by upgrading affected packages to version 1.7.3.
CVE-2021-42740 at a Glance
Security Impact
CVSS: 9.8
The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H).
How to Fix CVE-2021-42740
To remediate this vulnerability, upgrade all affected Shell quote dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.
npm install shell-quote@1.7.3
Run the following command in your project directory to verify that all resolved dependencies use the patched release:
npm ls shell-quote
How to Check if You Are Affected
To determine whether your Node.js application is affected by CVE-2021-42740, inspect your project dependencies using npm:
npm ls shell-quote
Analyze the terminal output to locate any version of Shell quote in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 1.7.3), your application is affected.
Note: The npm ls shell-quote 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-77: Improper Neutralization of Special Elements used in a Command ('Command Injection'), where the product constructs all or part of a command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended command when it is sent to a downstream component. In Shell quote, 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
CVE-2021-42740 Affected Shell quote Versions
1 component(s)| Product / Package | Ecosystem | Affected Versions | Fixed Version |
|---|---|---|---|
|
shell-quote
|
npm |
≥ 1.6.3
< 1.7.3
|
1.7.3
|
References
Frequently Asked Questions
What is CVE-2021-42740?
Which Shell quote versions are affected?
What version fixes CVE-2021-42740?
Is shell-quote affected?
What is the CVSS score of CVE-2021-42740?
What CWE is associated with CVE-2021-42740?
How can I check npm dependencies for CVE-2021-42740?
Machine-readable OSV JSON
OSV v1.5 Schema
{
"schema_version" : "1.4.0",
"id" : "GHSA-g4rg-993r-mgx7",
"modified" : "2025-09-10T17:27:08Z",
"published" : "2022-05-24T19:18:27Z",
"aliases" : [ "CVE-2021-42740" ],
"summary" : "Improper Neutralization of Special Elements used in a Command in Shell-quote",
"details" : "The shell-quote package before 1.7.3 for Node.js allows command injection. An attacker can inject unescaped shell metacharacters through a regex designed to support Windows drive letters. If the output of this package is passed to a real shell as a quoted argument to a command with `exec()`, an attacker can inject arbitrary commands. This is because the Windows drive letter regex character class is `[A-z]` instead of the correct `[A-Za-z]`. Several shell metacharacters exist in the space between capital letter Z and lower case letter a, such as the backtick character.",
"severity" : [ {
"type" : "CVSS_V3",
"score" : "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H"
} ],
"affected" : [ {
"package" : {
"ecosystem" : "npm",
"name" : "shell-quote"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "1.6.3"
}, {
"fixed" : "1.7.3"
} ]
} ],
"database_specific" : {
"last_known_affected_version_range" : "<= 1.7.2"
}
} ],
"references" : [ {
"type" : "ADVISORY",
"url" : "https://nvd.nist.gov/vuln/detail/CVE-2021-42740"
}, {
"type" : "WEB",
"url" : "https://github.com/ljharb/shell-quote/commit/5799416ed454aa4ec9afafc895b4e31760ea1abe"
}, {
"type" : "PACKAGE",
"url" : "https://github.com/ljharb/shell-quote"
}, {
"type" : "WEB",
"url" : "https://github.com/ljharb/shell-quote/blob/master/CHANGELOG.md#173"
}, {
"type" : "WEB",
"url" : "https://www.npmjs.com/package/shell-quote"
} ],
"database_specific" : {
"cwe_ids" : [ "CWE-77" ],
"severity" : "CRITICAL",
"github_reviewed" : true,
"github_reviewed_at" : "2022-06-21T20:08:10Z",
"nvd_published_at" : "2021-10-21T15:15:00Z"
}
}