CVE-2021-23382: Postcss Denial of Service Vulnerability
MODERATECVE-2021-23382 is a MODERATE (CVSS 5.3) denial of service vulnerability (CWE-400: Uncontrolled Resource Consumption) affecting Postcss libraries in the npm ecosystem. The issue involves regular expression denial of service in postcss. Remediation is available by upgrading affected packages to version 8.2.13, 7.0.36.
CVE-2021-23382 at a Glance
Security Impact
CVSS: 5.3
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:L).
How to Fix CVE-2021-23382
To remediate this vulnerability, upgrade all affected Postcss 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 postcss@8.2.13
npm install postcss@7.0.36
Run the following command in your project directory to verify that all resolved dependencies use the patched release:
npm ls postcss
How to Check if You Are Affected
To determine whether your Node.js application is affected by CVE-2021-23382, inspect your project dependencies using npm:
npm ls postcss
Analyze the terminal output to locate any version of Postcss in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 8.2.13), your application is affected.
Note: The npm ls postcss 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-400: Uncontrolled Resource Consumption, where the product does not properly control the allocation and maintenance of a limited resource. In Postcss, 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-2021-23382 Affected Postcss Versions
2 component(s)| Product / Package | Ecosystem | Affected Versions | Fixed Version |
|---|---|---|---|
|
postcss
|
npm |
≥ 8.0.0
< 8.2.13
|
8.2.13
|
|
postcss
|
npm |
< 7.0.36
|
7.0.36
|
References
Frequently Asked Questions
What is CVE-2021-23382?
Which Postcss versions are affected?
What version fixes CVE-2021-23382?
Is postcss affected?
What is the CVSS score of CVE-2021-23382?
What CWE is associated with CVE-2021-23382?
How can I check npm dependencies for CVE-2021-23382?
Machine-readable OSV JSON
OSV v1.5 Schema
{
"schema_version" : "1.4.0",
"id" : "GHSA-566m-qj78-rww5",
"modified" : "2023-09-08T19:35:12Z",
"published" : "2022-01-07T00:21:36Z",
"aliases" : [ "CVE-2021-23382" ],
"summary" : "Regular Expression Denial of Service in postcss",
"details" : "The package postcss versions before 7.0.36 or between 8.0.0 and 8.2.13 are vulnerable to Regular Expression Denial of Service (ReDoS) via getAnnotationURL() and loadAnnotation() in lib/previous-map.js. The vulnerable regexes are caused mainly by the sub-pattern \n```regex\n\\/\\*\\s* sourceMappingURL=(.*)\n```\n\n### PoC\n```js\nvar postcss = require(\"postcss\")\nfunction build_attack(n) {\n var ret = \"a{}\"\n for (var i = 0; i < n; i++) {\n ret += \"/*# sourceMappingURL=\"\n }\n return ret + \"!\";\n}\n```\n```js\npostcss.parse('a{}/*# sourceMappingURL=a.css.map */') for (var i = 1; i <= 500000; i++) {\n if (i % 1000 == 0) {\n var time = Date.now();\n var attack_str = build_attack(i) try {\n postcss.parse(attack_str) var time_cost = Date.now() - time;\n console.log(\"attack_str.length: \" + attack_str.length + \": \" + time_cost + \" ms\");\n } catch (e) {\n var time_cost = Date.now() - time;\n console.log(\"attack_str.length: \" + attack_str.length + \": \" + time_cost + \" ms\");\n }\n }\n}\n```",
"severity" : [ {
"type" : "CVSS_V3",
"score" : "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:L"
} ],
"affected" : [ {
"package" : {
"ecosystem" : "npm",
"name" : "postcss"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "8.0.0"
}, {
"fixed" : "8.2.13"
} ]
} ]
}, {
"package" : {
"ecosystem" : "npm",
"name" : "postcss"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "0"
}, {
"fixed" : "7.0.36"
} ]
} ]
} ],
"references" : [ {
"type" : "ADVISORY",
"url" : "https://nvd.nist.gov/vuln/detail/CVE-2021-23382"
}, {
"type" : "WEB",
"url" : "https://github.com/postcss/postcss/commit/2b1d04c867995e55124e0a165b7c6622c1735956"
}, {
"type" : "WEB",
"url" : "https://github.com/postcss/postcss/releases/tag/7.0.36"
}, {
"type" : "WEB",
"url" : "https://snyk.io/vuln/SNYK-JAVA-ORGWEBJARSNPM-1255641"
}, {
"type" : "WEB",
"url" : "https://snyk.io/vuln/SNYK-JS-POSTCSS-1255640"
} ],
"database_specific" : {
"cwe_ids" : [ "CWE-400" ],
"severity" : "MODERATE",
"github_reviewed" : true,
"github_reviewed_at" : "2021-05-20T21:23:19Z",
"nvd_published_at" : "2021-04-26T16:15:00Z"
}
}