Skip to content

Commit

Permalink
fix: Fixed a prototype pollution bug reported by @kevin_mizu
Browse files Browse the repository at this point in the history
  • Loading branch information
cure53 committed Jan 5, 2023
1 parent 24d2a7f commit d1dd037
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 13 deletions.
4 changes: 2 additions & 2 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.

4 changes: 2 additions & 2 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.

4 changes: 2 additions & 2 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.

2 changes: 1 addition & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export function clone(object) {

let property;
for (property in object) {
if (apply(hasOwnProperty, object, [property])) {
if (apply(hasOwnProperty, object, [property]) === true) {
newObject[property] = object[property];
}
}
Expand Down
12 changes: 11 additions & 1 deletion test/test-suite.js
Original file line number Diff line number Diff line change
Expand Up @@ -1687,7 +1687,7 @@
}
);
QUnit.test(
'Test protection from prototype pollution attacks',
'Test protection from prototype pollution attacks 1/2',
function (assert) {
const obj = JSON.parse(
'{"ALLOWED_ATTR":["onerror","src"], "documentMode":9}'
Expand All @@ -1701,6 +1701,16 @@
assert.equal(clean, '<img src="x">');
}
);
QUnit.test(
'Test protection from prototype pollution attacks 2/2',
function (assert) {
var obj = {};
obj.__proto__.hasOwnProperty = Object;
obj.constructor.prototype.ALLOWED_ATTR = ["src", "onerror"];
var clean = DOMPurify.sanitize('<img src=x onerror=alert(1)>');
assert.equal(clean, '<img src="x">');
}
);
QUnit.test('Test if namespaces are properly enforced', function (assert) {
var tests = [
{
Expand Down

0 comments on commit d1dd037

Please sign in to comment.