Skip to content

Commit

Permalink
fix: Address prototype pollution vulnerability in merge function
Browse files Browse the repository at this point in the history
  • Loading branch information
ohad2712 committed Jul 5, 2021
1 parent 238137e commit 29851b6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ function merge(target, additional) {
each(additional, function objectForEach(key, value) {
if (target[key] === undefined) {
result[key] = value;
} else {
} else if (Object.hasOwnProperty.call(target, key)){
result[key] = merge(target[key], additional[key]);
}
});
Expand Down
8 changes: 8 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,4 +181,12 @@ describe('predefine', function () {
assume(calls).to.equal(1);
});
});

describe('.merge', function () {
it('avoids prototype polluting', function () {
predefine.merge({}, JSON.parse('{"__proto__": {"a": "b"}}'));

assume(({}).a).to.be.undefined();
});
});
});

0 comments on commit 29851b6

Please sign in to comment.