Skip to content

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

High severity GitHub Reviewed Published Jul 15, 2022 in ericcornelissen/shescape • Updated Apr 6, 2023

Package

npm shescape (npm)

Affected versions

< 1.5.8

Patched versions

1.5.8

Description

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:

References

Published to the GitHub Advisory Database Jul 15, 2022
Reviewed Jul 15, 2022
Published by the National Vulnerability Database Aug 1, 2022
Last updated Apr 6, 2023

Severity

High

CVSS overall score

This score calculates overall vulnerability severity from 0 to 10 and is based on the Common Vulnerability Scoring System (CVSS).
/ 10

CVSS v3 base metrics

Attack vector
Network
Attack complexity
High
Privileges required
None
User interaction
None
Scope
Changed
Confidentiality
Low
Integrity
Low
Availability
High

CVSS v3 base metrics

Attack vector: More severe the more the remote (logically and physically) an attacker can be in order to exploit the vulnerability.
Attack complexity: More severe for the least complex attacks.
Privileges required: More severe if no privileges are required.
User interaction: More severe when no user interaction is required.
Scope: More severe when a scope change occurs, e.g. one vulnerable component impacts resources in components beyond its security scope.
Confidentiality: More severe when loss of data confidentiality is highest, measuring the level of data access available to an unauthorized user.
Integrity: More severe when loss of data integrity is the highest, measuring the consequence of data modification possible by an unauthorized user.
Availability: More severe when the loss of impacted component availability is highest.
CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:C/C:L/I:L/A:H

EPSS score

0.273%
(69th percentile)

Weaknesses

CVE ID

CVE-2022-31179

GHSA ID

GHSA-jjc5-fp7p-6f8w

Credits

Loading Checking history
See something to contribute? Suggest improvements for this vulnerability.