Skip to content

Commit

Permalink
fix: prototype pollution in _.defaultsDeep (#4336)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kirill89 authored and jdalton committed Jun 24, 2019
1 parent e42cd97 commit 1f8ea07
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lodash.js
Expand Up @@ -6589,14 +6589,18 @@
}

/**
* Gets the value at `key`, unless `key` is "__proto__".
* Gets the value at `key`, unless `key` is "__proto__" or "constructor".
*
* @private
* @param {Object} object The object to query.
* @param {string} key The key of the property to get.
* @returns {*} Returns the property value.
*/
function safeGet(object, key) {
if (key === 'constructor' && typeof object[key] === 'function') {
return;
}

if (key == '__proto__') {
return;
}
Expand Down
11 changes: 11 additions & 0 deletions test/test.js
Expand Up @@ -4712,6 +4712,17 @@
var actual = _.defaultsDeep({ 'a': ['abc'] }, { 'a': 'abc' });
assert.deepEqual(actual.a, ['abc']);
});

QUnit.test('should not indirectly merge `Object` properties', function(assert) {
assert.expect(1);

_.defaultsDeep({}, { 'constructor': { 'a': 1 } });

var actual = 'a' in Object;
delete Object.a;

assert.notOk(actual);
});
}());

/*--------------------------------------------------------------------------*/
Expand Down

0 comments on commit 1f8ea07

Please sign in to comment.