CVE-2022-25918: Shescape Inefficient Regular Expression Complexity Vulnerability
HIGHCVE-2022-25918 is a HIGH (CVSS 7.5) inefficient regular expression complexity vulnerability (CWE-1333: Inefficient Regular Expression Complexity) affecting Shescape libraries in the npm ecosystem. The issue involves inefficient regular expression complexity in shescape. Remediation is available by upgrading affected packages to version 1.6.1.
CVE-2022-25918 at a Glance
Security Impact
CVSS: 7.5
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:N/I:N/A:H).
How to Fix CVE-2022-25918
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.
npm install shescape@1.6.1
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-2022-25918, 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.6.1), 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-1333: Inefficient Regular Expression Complexity, where the product uses a regular expression with a worst-case computational complexity that is inefficient and possibly exponential. 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
CVE-2022-25918 Affected Shescape Versions
1 component(s)| Product / Package | Ecosystem | Affected Versions | Fixed Version |
|---|---|---|---|
|
shescape
|
npm |
≥ 1.5.10
< 1.6.1
|
1.6.1
|
References
Frequently Asked Questions
What is CVE-2022-25918?
Which Shescape versions are affected?
What version fixes CVE-2022-25918?
Is shescape affected?
What is the CVSS score of CVE-2022-25918?
What CWE is associated with CVE-2022-25918?
How can I check npm dependencies for CVE-2022-25918?
Machine-readable OSV JSON
OSV v1.5 Schema
{
"schema_version" : "1.4.0",
"id" : "GHSA-cr84-xvw4-qx3c",
"modified" : "2022-10-31T16:02:55Z",
"published" : "2022-10-25T22:27:32Z",
"aliases" : [ "CVE-2022-25918" ],
"summary" : "Inefficient Regular Expression Complexity in shescape ",
"details" : "### Impact\n\nThis impacts users that use shescape to escape arguments:\n\n- for the Unix shell Bash, or any not-officially-supported Unix shell;\n- using the `escape` or `escapeAll` functions with the `interpolation` option set to `true`.\n\nAn attacker can cause polynomial backtracking in terms of the input string length due to a Regular Expression in shescape that is vulnerable to Regular Expression Denial of Service (ReDoS). Example:\n\n```javascript\nimport * as shescape from \"shescape\";\n\n/* 1. Prerequisites */\nconst options = {\n interpolation: true,\n // and\n shell: \"/bin/bash\",\n // or\n shell: \"some-not-officially-supported-shell\",\n // or\n shell: undefined, // Only if the system's default shell is bash or an unsupported shell.\n};\n\n/* 2. Attack */\nlet userInput = '{,'.repeat(150_000); // polynomial backtracking\n\n/* 3. Usage */\nshescape.escape(userInput, options);\n// or\nshescape.escapeAll([userInput], options);\n```\n\n### Patches\n\nThis bug has been patched in [v1.6.1](https://github.com/ericcornelissen/shescape/releases/tag/v1.6.1) which you can upgrade to now. No further changes required.\n\n### Workarounds\n\nAlternatively, a maximum length can be enforced on input strings to shescape to reduce the impact of the vulnerability. It is not recommended to try and detect vulnerable input strings, as the logic for this may end up being vulnerable to ReDoS itself.\n\n### References\n\n- Shescape commit [552e8ea](https://github.com/ericcornelissen/shescape/commit/552e8eab56861720b1d4e5474fb65741643358f9)\n- Shescape Release [v1.6.1](https://github.com/ericcornelissen/shescape/releases/tag/v1.6.1)\n\n### For more information\n\n- Comment on commit [552e8ea](https://github.com/ericcornelissen/shescape/commit/552e8eab56861720b1d4e5474fb65741643358f9)\n- Open an issue at [https://github.com/ericcornelissen/shescape/issues](https://github.com/ericcornelissen/shescape/issues?q=is%3Aissue+is%3Aopen) (New issue > Question > Get started)\n",
"severity" : [ {
"type" : "CVSS_V3",
"score" : "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H"
} ],
"affected" : [ {
"package" : {
"ecosystem" : "npm",
"name" : "shescape"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "1.5.10"
}, {
"fixed" : "1.6.1"
} ]
} ]
} ],
"references" : [ {
"type" : "WEB",
"url" : "https://github.com/ericcornelissen/shescape/security/advisories/GHSA-cr84-xvw4-qx3c"
}, {
"type" : "ADVISORY",
"url" : "https://nvd.nist.gov/vuln/detail/CVE-2022-25918"
}, {
"type" : "WEB",
"url" : "https://github.com/ericcornelissen/shescape/commit/552e8eab56861720b1d4e5474fb65741643358f9"
}, {
"type" : "PACKAGE",
"url" : "https://github.com/ericcornelissen/shescape"
}, {
"type" : "WEB",
"url" : "https://github.com/ericcornelissen/shescape/blob/main/src/unix.js%23L52"
}, {
"type" : "WEB",
"url" : "https://github.com/ericcornelissen/shescape/releases/tag/v1.6.1"
}, {
"type" : "WEB",
"url" : "https://security.snyk.io/vuln/SNYK-JS-SHESCAPE-3061108"
} ],
"database_specific" : {
"cwe_ids" : [ "CWE-1333" ],
"severity" : "HIGH",
"github_reviewed" : true,
"github_reviewed_at" : "2022-10-25T22:27:32Z",
"nvd_published_at" : "2022-10-27T10:15:00Z"
}
}