CVE-2021-21384: Shescape Null Characters Not Escaped Vulnerability

HIGH
Advisory Identifier: GHSA-f2rp-38vg-j3gh
CVSS 6.3
CWE-88
Published
Advisory Summary

CVE-2021-21384 is a HIGH (CVSS 6.3) null characters not escaped vulnerability (CWE-88: Improper Neutralization of Argument Delimiters in a Command ('Argument Injection')) affecting Shescape libraries in the npm ecosystem. The issue involves null characters not escaped. Remediation is available by upgrading affected packages to version 1.1.3.

CVE-2021-21384 at a Glance

CVE Identifier CVE-2021-21384
GHSA Identifier GHSA-f2rp-38vg-j3gh
Severity HIGH
CVSS v3.1 Base Score 6.3
CWE Classification CWE-88: Improper Neutralization of Argument Delimiters in a Command ('Argument Injection')
Affected Product Shescape
Package Ecosystem npm
Published Date
Last Updated

Security Impact

CVSS: 6.3

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

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

How to Fix CVE-2021-21384

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

shescape fixed: 1.1.3
npm install shescape@1.1.3
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 shescape

How to Check if You Are Affected

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

npm ls shescape

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

Note: The npm ls shescape 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-88: Improper Neutralization of Argument Delimiters in a Command ('Argument Injection'), where the product constructs a string for a command to be executed by a separate component in another control sphere, but it does not properly delimit the intended arguments, options, or switches within that command string. In Shescape, 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

### Impact Anyone using _Shescape_ to defend against shell injection may still be vulnerable against shell injection if the attacker manages to insert a [null character](https://en.wikipedia.org/wiki/Null_character) into the payload. For example (on Windows): ```javascript const cp = require("child_process"); const shescape = require("shescape"); const nullChar = String.fromCharCode(0); const payload = "foo\" && ls -al ${nullChar} && echo \"bar"; console.log(cp.execSync(`echo ${shescape.quote(payload)}`)); // foototal 3 // drwxr-xr-x 1 owner XXXXXX 0 Mar 13 18:44 . // drwxr-xr-x 1 owner XXXXXX 0 Mar 13 00:09 .. // drwxr-xr-x 1 owner XXXXXX 0 Mar 13 18:42 folder // -rw-r--r-- 1 owner XXXXXX 0 Mar 13 18:42 file ``` ### Patches The problem has been patched in [v1.1.3](https://github.com/ericcornelissen/shescape/releases/tag/v1.1.3) which you can upgrade to now. No further changes are required. ### Workarounds Alternatively, null characters can be stripped out manually using e.g. `arg.replace(/\u{0}/gu, "")`

CVE-2021-21384 Affected Shescape Versions

1 component(s)
Fixed Versions:
1.1.3
Product / Package Ecosystem Affected Versions Fixed Version
shescape
npm
< 1.1.3
1.1.3

References

Frequently Asked Questions

What is CVE-2021-21384?
CVE-2021-21384 is a security vulnerability in Shescape involving Null characters not escaped under CWE-88: Improper Neutralization of Argument Delimiters in a Command ('Argument Injection').
Which Shescape versions are affected?
Affected versions include releases prior to 1.1.3 across affected packages: shescape.
What version fixes CVE-2021-21384?
Upgrading to 1.1.3 (or the latest patched release for your respective branch) resolves the vulnerability.
Is shescape affected?
Yes, shescape is affected in releases prior to 1.1.3. Upgrade your dependency to 1.1.3 or later.
What is the CVSS score of CVE-2021-21384?
CVE-2021-21384 has a CVSS v3.1 base score of 6.3 (HIGH) with vector string CVSS:3.1/AV:L/AC:H/PR:N/UI:R/S:C/C:L/I:H/A:N.
What CWE is associated with CVE-2021-21384?
CVE-2021-21384 is classified under CWE-88: Improper Neutralization of Argument Delimiters in a Command ('Argument Injection') (The product constructs a string for a command to be executed by a separate component in another control sphere, but it does not properly delimit the intended arguments, options, or switches within that command string.).
How can I check npm dependencies for CVE-2021-21384?
Run the dependency tree command: 'npm ls shescape'. 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-f2rp-38vg-j3gh",
  "modified" : "2021-03-18T23:43:39Z",
  "published" : "2021-03-18T23:47:56Z",
  "aliases" : [ "CVE-2021-21384" ],
  "summary" : "Null characters not escaped",
  "details" : "### Impact\n\nAnyone using _Shescape_ to defend against shell injection may still be vulnerable against shell injection if the attacker manages to insert a [null character](https://en.wikipedia.org/wiki/Null_character) into the payload. For example (on Windows):\n\n```javascript\nconst cp = require(\"child_process\");\nconst shescape = require(\"shescape\");\n\nconst nullChar = String.fromCharCode(0);\nconst payload = \"foo\\\" && ls -al ${nullChar} && echo \\\"bar\";\nconsole.log(cp.execSync(`echo ${shescape.quote(payload)}`));\n// foototal 3\n// drwxr-xr-x 1 owner XXXXXX      0 Mar 13 18:44 .\n// drwxr-xr-x 1 owner XXXXXX      0 Mar 13 00:09 ..\n// drwxr-xr-x 1 owner XXXXXX      0 Mar 13 18:42 folder                                                                 \n// -rw-r--r-- 1 owner XXXXXX      0 Mar 13 18:42 file\n```\n\n### Patches\n\nThe problem has been patched in [v1.1.3](https://github.com/ericcornelissen/shescape/releases/tag/v1.1.3) which you can upgrade to now. No further changes are required.\n\n### Workarounds\n\nAlternatively, null characters can be stripped out manually using e.g. `arg.replace(/\\u{0}/gu, \"\")`",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:L/AC:H/PR:N/UI:R/S:C/C:L/I:H/A:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "npm",
      "name" : "shescape"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "1.1.3"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/ericcornelissen/shescape/security/advisories/GHSA-f2rp-38vg-j3gh"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2021-21384"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/ericcornelissen/shescape/commit/07a069a66423809cbedd61d980c11ca44a29ea2b"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/ericcornelissen/shescape/releases/tag/v1.1.3"
  }, {
    "type" : "WEB",
    "url" : "https://www.npmjs.com/package/shescape"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-88" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2021-03-18T23:43:39Z",
    "nvd_published_at" : "2021-03-19T00:15:00Z"
  }
}