Ecosyste.ms: Advisories

An open API service providing security vulnerability metadata for many open source software ecosystems.

Security Advisories: GSA_kwCzR0hTQS1qamM1LWZwN3AtNmY4d84AAtaD

Shescape prior to 1.5.8 vulnerable to insufficient escaping of line feeds for CMD

Impact

This impacts users that use Shescape (any API function) to escape arguments for cmd.exe on Windows. An attacker can omit all arguments following their input by including a line feed character ('\n') in the payload. Example:

import cp from "node:child_process";
import * as shescape from "shescape";

// 1. Prerequisites
const options = {
  shell: "cmd.exe",
};

// 2. Attack
const payload = "attacker\n";

// 3. Usage
let escapedPayload;
escapedPayload = shescape.escape(payload, options);
// Or
escapedPayload = shescape.escapeAll([payload], options)[0];
// Or
escapedPayload = shescape.quote(payload, options);
// Or
escapedPayload = shescape.quoteAll([payload], options)[0];

cp.execSync(`echo Hello ${escapedPayload}! How are you doing?`, options);
// Outputs:  "Hello attacker"

Note: execSync is just illustrative here, all of exec, execFile, execFileSync, fork, spawn, and spawnSync can be attacked using a line feed character if CMD is the shell being used.

Patches

This bug has been patched in v1.5.8 which you can upgrade to now. No further changes are required.

Workarounds

Alternatively, line feed characters ('\n') can be stripped out manually or the user input can be made the last argument (this only limits the impact).

References

For more information

If you have any questions or comments about this advisory:

Permalink: https://github.com/advisories/GHSA-jjc5-fp7p-6f8w
JSON: https://advisories.ecosyste.ms/api/v1/advisories/GSA_kwCzR0hTQS1qamM1LWZwN3AtNmY4d84AAtaD
Source: GitHub Advisory Database
Origin: Unspecified
Severity: High
Classification: General
Published: almost 2 years ago
Updated: about 1 year ago


CVSS Score: 8.1
CVSS vector: CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:C/C:L/I:L/A:H

Identifiers: GHSA-jjc5-fp7p-6f8w, CVE-2022-31179
References: Repository: https://github.com/ericcornelissen/shescape
Blast Radius: 11.7

Affected Packages

npm:shescape
Dependent packages: 15
Dependent repositories: 28
Downloads: 15,574 last month
Affected Version Ranges: < 1.5.8
Fixed in: 1.5.8
All affected versions: 0.1.0, 0.2.0, 0.2.1, 0.3.0, 0.3.1, 0.4.0, 0.4.1, 1.0.0, 1.1.0, 1.1.1, 1.1.2, 1.1.3, 1.2.0, 1.2.1, 1.3.0, 1.3.1, 1.3.2, 1.3.3, 1.4.0, 1.5.0, 1.5.1, 1.5.2, 1.5.3, 1.5.4, 1.5.5, 1.5.6, 1.5.7
All unaffected versions: 1.5.8, 1.5.9, 1.5.10, 1.6.0, 1.6.1, 1.6.2, 1.6.3, 1.6.4, 1.6.5, 1.6.6, 1.6.7, 1.7.0, 1.7.1, 1.7.2, 1.7.3, 1.7.4, 2.0.0, 2.0.1, 2.0.2, 2.1.0