LOW 3.1 npm
Shescape potential environment variable exposure on Windows with CMD
GHSA-3g7p-8qhx-mc8r · CVE-2023-35931
Published · Modified
AI SAST
Find this class of vulnerability in your own code
Corgea's AI-native static analysis detects vulnerabilities like this one across your repositories, ranks them by exploitability, and returns review-ready fixes.
Description
Impact
This impact users of Shescape:
- On Windows using the Windows Command Prompt (i.e.
cmd.exe), and - Using
quote/quoteAllorescape/escapeAllwith theinterpolationoption set totrue.
An attacker may be able to get read-only access to environment variables. Example:
import * as cp from "node:child_process";
import * as shescape from "shescape";
// 1. Prerequisites
const options = {
shell: "cmd.exe",
// Or
shell: undefined, // Only if the default shell is CMD
// And
interpolation: true, // Only applies to `escape` and `escapeAll` usage
}
// 2. Attack (one of many)
const payload = "%PATH%";
// 3. Usage
let escapedPayload;
escapedPayload = shescape.quote(payload, options);
// Or
escapedPayload = shescape.quoteAll([payload], options);
// Or
escapedPayload = shescape.escape(payload, options);
// Or
escapedPayload = shescape.escapeAll([payload], options);
// And (example)
const result = cp.execSync(`echo Hello ${escapedPayload}`, options);
// 4. Impact
console.log(result.toString());
// Outputs "Hello" followed by the contents of the PATH environment variable
Patches
This bug has been patched in v1.7.1 which you can upgrade to now. No further changes are required.
Workarounds
Alternatively, users can remove all instances of % from user input, either before or after using Shescape.
References
References
- WEB https://github.com/ericcornelissen/shescape/security/advisories/GHSA-3g7p-8qhx-mc8r
- ADVISORY https://nvd.nist.gov/vuln/detail/CVE-2023-35931
- WEB https://github.com/ericcornelissen/shescape/pull/982
- WEB https://github.com/ericcornelissen/shescape/commit/d0fce70f987ac0d8331f93cb45d47e79436173ac
- PACKAGE https://github.com/ericcornelissen/shescape
- WEB https://github.com/ericcornelissen/shescape/releases/tag/v1.7.1
Ready to move
Start Securing
Free, no credit card | First findings in minutes