html-minifier-next 1.0.1 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +77 -14
- package/cli.js +3 -1
- package/dist/htmlminifier.cjs +23 -2
- package/dist/htmlminifier.esm.bundle.js +2950 -806
- package/dist/htmlminifier.umd.bundle.js +2950 -806
- package/dist/htmlminifier.umd.bundle.min.js +3 -3
- package/package.json +13 -17
- package/src/htmlminifier.js +23 -2
package/package.json
CHANGED
|
@@ -6,36 +6,32 @@
|
|
|
6
6
|
"bugs": "https://github.com/j9t/html-minifier-next/issues",
|
|
7
7
|
"dependencies": {
|
|
8
8
|
"change-case": "^4.1.2",
|
|
9
|
-
"clean-css": "~5.3.
|
|
10
|
-
"commander": "^
|
|
11
|
-
"entities": "^6.0.
|
|
9
|
+
"clean-css": "~5.3.3",
|
|
10
|
+
"commander": "^14.0.0",
|
|
11
|
+
"entities": "^6.0.1",
|
|
12
12
|
"relateurl": "^0.2.7",
|
|
13
|
-
"terser": "^5.
|
|
13
|
+
"terser": "^5.39.2"
|
|
14
14
|
},
|
|
15
15
|
"description": "Highly configurable, well-tested, JavaScript-based HTML minifier.",
|
|
16
16
|
"devDependencies": {
|
|
17
17
|
"@commitlint/cli": "^19.8.1",
|
|
18
|
-
"@jest/globals": "^
|
|
18
|
+
"@jest/globals": "^30.0.0",
|
|
19
19
|
"@rollup/plugin-commonjs": "^28.0.3",
|
|
20
20
|
"@rollup/plugin-json": "^6.1.0",
|
|
21
21
|
"@rollup/plugin-node-resolve": "^16.0.1",
|
|
22
22
|
"@rollup/plugin-terser": "^0.4.4",
|
|
23
|
-
"alpinejs": "^3.
|
|
23
|
+
"alpinejs": "^3.14.9",
|
|
24
24
|
"commitlint-config-non-conventional": "^1.0.1",
|
|
25
|
-
"eslint": "^
|
|
26
|
-
"eslint-config-standard": "^17.1.0",
|
|
25
|
+
"eslint": "^9.29.0",
|
|
27
26
|
"husky": "^9.1.7",
|
|
28
27
|
"is-ci": "^4.1.0",
|
|
29
|
-
"jest": "^
|
|
30
|
-
"jest-environment-jsdom": "^
|
|
31
|
-
"lint-staged": "^16.
|
|
32
|
-
"rollup": "^
|
|
28
|
+
"jest": "^30.0.0",
|
|
29
|
+
"jest-environment-jsdom": "^30.0.0",
|
|
30
|
+
"lint-staged": "^16.1.0",
|
|
31
|
+
"rollup": "^4.41.1",
|
|
33
32
|
"rollup-plugin-polyfill-node": "^0.13.0",
|
|
34
33
|
"vite": "^6.3.5"
|
|
35
34
|
},
|
|
36
|
-
"engines": {
|
|
37
|
-
"node": ">=16.0.0"
|
|
38
|
-
},
|
|
39
35
|
"exports": {
|
|
40
36
|
".": {
|
|
41
37
|
"import": "./src/htmlminifier.js",
|
|
@@ -81,7 +77,7 @@
|
|
|
81
77
|
"build": "rollup -c",
|
|
82
78
|
"build:docs": "vite build --base /html-minifier-next/ --outDir build",
|
|
83
79
|
"deploy": "npm run build && npm run build:docs",
|
|
84
|
-
"lint": "eslint .
|
|
80
|
+
"lint": "eslint .",
|
|
85
81
|
"prepare": "husky",
|
|
86
82
|
"serve": "npm run build && vite",
|
|
87
83
|
"test": "npm run test:node",
|
|
@@ -90,5 +86,5 @@
|
|
|
90
86
|
"test:web": "NODE_OPTIONS='--experimental-vm-modules --no-warnings' jest --verbose --environment=jsdom"
|
|
91
87
|
},
|
|
92
88
|
"type": "module",
|
|
93
|
-
"version": "1.
|
|
89
|
+
"version": "1.1.2"
|
|
94
90
|
}
|
package/src/htmlminifier.js
CHANGED
|
@@ -844,6 +844,11 @@ async function createSortFns(value, options, uidIgnore, uidAttr) {
|
|
|
844
844
|
}
|
|
845
845
|
|
|
846
846
|
async function minifyHTML(value, options, partialMarkup) {
|
|
847
|
+
// Check input length limitation to prevent ReDoS attacks
|
|
848
|
+
if (options.maxInputLength && value.length > options.maxInputLength) {
|
|
849
|
+
throw new Error(`Input length (${value.length}) exceeds maximum allowed length (${options.maxInputLength})`);
|
|
850
|
+
}
|
|
851
|
+
|
|
847
852
|
if (options.collapseWhitespace) {
|
|
848
853
|
value = collapseWhitespace(value, options, true, true);
|
|
849
854
|
}
|
|
@@ -888,8 +893,24 @@ async function minifyHTML(value, options, partialMarkup) {
|
|
|
888
893
|
return re.source;
|
|
889
894
|
});
|
|
890
895
|
if (customFragments.length) {
|
|
891
|
-
|
|
892
|
-
|
|
896
|
+
// Warn about potential ReDoS if custom fragments use unlimited quantifiers
|
|
897
|
+
for (let i = 0; i < customFragments.length; i++) {
|
|
898
|
+
if (/[*+]/.test(customFragments[i])) {
|
|
899
|
+
options.log('Warning: Custom fragment contains unlimited quantifiers (* or +) which may cause ReDoS vulnerability');
|
|
900
|
+
break;
|
|
901
|
+
}
|
|
902
|
+
}
|
|
903
|
+
|
|
904
|
+
// Safe approach: Use bounded quantifiers instead of unlimited ones to prevent ReDoS
|
|
905
|
+
const maxQuantifier = options.customFragmentQuantifierLimit || 200;
|
|
906
|
+
const whitespacePattern = `\\s{0,${maxQuantifier}}`;
|
|
907
|
+
|
|
908
|
+
// Use bounded quantifiers to prevent ReDoS - this approach prevents exponential backtracking
|
|
909
|
+
const reCustomIgnore = new RegExp(
|
|
910
|
+
whitespacePattern + '(?:' + customFragments.join('|') + '){1,' + maxQuantifier + '}' + whitespacePattern,
|
|
911
|
+
'g'
|
|
912
|
+
);
|
|
913
|
+
// Temporarily replace custom ignored fragments with unique attributes
|
|
893
914
|
value = value.replace(reCustomIgnore, function (match) {
|
|
894
915
|
if (!uidAttr) {
|
|
895
916
|
uidAttr = uniqueId(value);
|