Skip to content

Commit

Permalink
fix: Merged prototype pollution check into 2.x
Browse files Browse the repository at this point in the history
  • Loading branch information
cure53 committed May 11, 2024
1 parent 481ff8e commit 26e1d69
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 21 deletions.
15 changes: 11 additions & 4 deletions dist/purify.cjs.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/purify.cjs.js.map

Large diffs are not rendered by default.

15 changes: 11 additions & 4 deletions dist/purify.es.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/purify.es.js.map

Large diffs are not rendered by default.

15 changes: 11 additions & 4 deletions dist/purify.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/purify.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/purify.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/purify.min.js.map

Large diffs are not rendered by default.

21 changes: 17 additions & 4 deletions src/purify.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
stringToString,
stringIndexOf,
stringTrim,
numberIsNaN,
regExpTest,
typeErrorCreate,
lookupGetter,
Expand Down Expand Up @@ -1403,8 +1404,14 @@ function createDOMPurify(window = getGlobal()) {
}
}

/* Remove an element if nested too deeply to avoid mXSS */
if (shadowNode.__depth >= MAX_NESTING_DEPTH) {
/*
* Remove an element if nested too deeply to avoid mXSS
* or if the __depth might have been tampered with
*/
if (
shadowNode.__depth >= MAX_NESTING_DEPTH ||
numberIsNaN(shadowNode.__depth)
) {
_forceRemove(shadowNode);
}

Expand Down Expand Up @@ -1570,8 +1577,14 @@ function createDOMPurify(window = getGlobal()) {
}
}

/* Remove an element if nested too deeply to avoid mXSS */
if (currentNode.__depth >= MAX_NESTING_DEPTH) {
/*
* Remove an element if nested too deeply to avoid mXSS
* or if the __depth might have been tampered with
*/
if (
currentNode.__depth >= MAX_NESTING_DEPTH ||
numberIsNaN(currentNode.__depth)
) {
_forceRemove(currentNode);
}

Expand Down
4 changes: 4 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ const regExpTest = unapply(RegExp.prototype.test);

const typeErrorCreate = unconstruct(TypeError);

const numberIsNaN = unapply(Number.isNaN);

export function unapply(func) {
return (thisArg, ...args) => apply(func, thisArg, args);
}
Expand Down Expand Up @@ -155,6 +157,8 @@ export {
stringToLowerCase,
stringToString,
stringTrim,
// Number
numberIsNaN,
// Errors
typeErrorCreate,
// Other
Expand Down

0 comments on commit 26e1d69

Please sign in to comment.