Skip to content

Commit

Permalink
Release 4.3.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean-Philippe Zolesio committed Nov 30, 2023
1 parent 49bc539 commit 472bef9
Show file tree
Hide file tree
Showing 8 changed files with 551 additions and 495 deletions.
7 changes: 7 additions & 0 deletions History.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
4.3.2 / 2023-11-28
==================

* Fix redos vulnerability with specific crafted css string - CVE-2023-48631
* Fix Problem parsing with :is() and nested :nth-child() #211


4.3.1 / 2023-03-14
==================

Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@adobe/css-tools",
"version": "4.3.1",
"version": "4.3.2",
"description": "CSS parser / stringifier",
"source": "src/index.ts",
"main": "./dist/index.cjs",
Expand All @@ -16,8 +16,8 @@
"Readme.md"
],
"devDependencies": {
"@parcel/packager-ts": "2.9.3",
"@parcel/transformer-typescript-types": "2.9.3",
"@parcel/packager-ts": "2.10.3",
"@parcel/transformer-typescript-types": "2.10.3",
"@types/benchmark": "^2.1.1",
"@types/bytes": "^3.1.1",
"@types/jest": "^29.5.3",
Expand All @@ -26,7 +26,7 @@
"bytes": "^3.1.0",
"gts": "^5.0.0",
"jest": "^29.6.2",
"parcel": "^2.9.3",
"parcel": "^2.10.3",
"ts-jest": "^29.1.1",
"typescript": "^5.0.2"
},
Expand Down
8 changes: 5 additions & 3 deletions src/parse/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,15 +227,17 @@ export const parse = (
*
* Regex logic:
* ("|')(?:\\\1|.)*?\1 => Handle the " and '
* \(.*?\) => Handle the ()
* \(.*?\(\(.*?\))*) => Handle the () and the (())
*
* Optimization 1:
* No greedy capture (see docs about the difference between .* and .*?)
*
* Optimization 2:
* ("|')(?:\\\1|.)*?\1 this use reference to capture group, it work faster.
*/
.replace(/("|')(?:\\\1|.)*?\1|\(.*?\)/g, m => m.replace(/,/g, '\u200C'))
.replace(/("|')(?:\\\1|.)*?\1|\(.*?(\(.*?\))*\)/g, m =>

Check failure

Code scanning / CodeQL

Inefficient regular expression High

This part of the regular expression may cause exponential backtracking on strings starting with '((' and containing many repetitions of ')('.
m.replace(/,/g, '\u200C')
)
// Split the selector by ','
.split(',')
// Replace back \u200C by ','
Expand Down Expand Up @@ -522,7 +524,7 @@ export const parse = (
*/
function atcustommedia(): CssCustomMediaAST | void {
const pos = position();
const m = match(/^@custom-media\s+(--[^\s]+)\s*([^{;]+);/);
const m = match(/^@custom-media\s+(--\S+)\s*([^{;\s][^{;]*);/);
if (!m) {
return;
}
Expand Down
42 changes: 42 additions & 0 deletions test/cases/selector-double-is/ast.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"type": "stylesheet",
"stylesheet": {
"rules": [
{
"type": "rule",
"selectors": [
".klass:is(:nth-child(1), :nth-child(2))"
],
"declarations": [
{
"type": "declaration",
"property": "margin",
"value": "0 !important",
"position": {
"start": {
"line": 1,
"column": 42
},
"end": {
"line": 1,
"column": 62
},
"source": "input.css"
}
}
],
"position": {
"start": {
"line": 1,
"column": 1
},
"end": {
"line": 1,
"column": 63
},
"source": "input.css"
}
}
]
}
}
1 change: 1 addition & 0 deletions test/cases/selector-double-is/compressed.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.klass:is(:nth-child(1), :nth-child(2)){margin:0 !important;}
1 change: 1 addition & 0 deletions test/cases/selector-double-is/input.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.klass:is(:nth-child(1), :nth-child(2)) {margin: 0 !important}
3 changes: 3 additions & 0 deletions test/cases/selector-double-is/output.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.klass:is(:nth-child(1), :nth-child(2)) {
margin: 0 !important;
}
Loading

0 comments on commit 472bef9

Please sign in to comment.