Skip to content

Commit 26e1d69

Browse files
committed
fix: Merged prototype pollution check into 2.x
1 parent 481ff8e commit 26e1d69

File tree

10 files changed

+59
-21
lines changed

10 files changed

+59
-21
lines changed

dist/purify.cjs.js

Lines changed: 11 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/purify.cjs.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/purify.es.js

Lines changed: 11 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/purify.es.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/purify.js

Lines changed: 11 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/purify.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/purify.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/purify.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/purify.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
stringToString,
1515
stringIndexOf,
1616
stringTrim,
17+
numberIsNaN,
1718
regExpTest,
1819
typeErrorCreate,
1920
lookupGetter,
@@ -1403,8 +1404,14 @@ function createDOMPurify(window = getGlobal()) {
14031404
}
14041405
}
14051406

1406-
/* Remove an element if nested too deeply to avoid mXSS */
1407-
if (shadowNode.__depth >= MAX_NESTING_DEPTH) {
1407+
/*
1408+
* Remove an element if nested too deeply to avoid mXSS
1409+
* or if the __depth might have been tampered with
1410+
*/
1411+
if (
1412+
shadowNode.__depth >= MAX_NESTING_DEPTH ||
1413+
numberIsNaN(shadowNode.__depth)
1414+
) {
14081415
_forceRemove(shadowNode);
14091416
}
14101417

@@ -1570,8 +1577,14 @@ function createDOMPurify(window = getGlobal()) {
15701577
}
15711578
}
15721579

1573-
/* Remove an element if nested too deeply to avoid mXSS */
1574-
if (currentNode.__depth >= MAX_NESTING_DEPTH) {
1580+
/*
1581+
* Remove an element if nested too deeply to avoid mXSS
1582+
* or if the __depth might have been tampered with
1583+
*/
1584+
if (
1585+
currentNode.__depth >= MAX_NESTING_DEPTH ||
1586+
numberIsNaN(currentNode.__depth)
1587+
) {
15751588
_forceRemove(currentNode);
15761589
}
15771590

src/utils.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ const regExpTest = unapply(RegExp.prototype.test);
5050

5151
const typeErrorCreate = unconstruct(TypeError);
5252

53+
const numberIsNaN = unapply(Number.isNaN);
54+
5355
export function unapply(func) {
5456
return (thisArg, ...args) => apply(func, thisArg, args);
5557
}
@@ -155,6 +157,8 @@ export {
155157
stringToLowerCase,
156158
stringToString,
157159
stringTrim,
160+
// Number
161+
numberIsNaN,
158162
// Errors
159163
typeErrorCreate,
160164
// Other

0 commit comments

Comments
 (0)