mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-29 06:27:49 +00:00
fix: prototype pollution in _.defaultsDeep (#4336)
This commit is contained in:
committed by
John-David Dalton
parent
e42cd97dae
commit
1f8ea07746
@@ -6589,7 +6589,7 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
@@ -6597,6 +6597,10 @@
|
||||
* @returns {*} Returns the property value.
|
||||
*/
|
||||
function safeGet(object, key) {
|
||||
if (key === 'constructor' && typeof object[key] === 'function') {
|
||||
return;
|
||||
}
|
||||
|
||||
if (key == '__proto__') {
|
||||
return;
|
||||
}
|
||||
|
||||
11
test/test.js
11
test/test.js
@@ -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);
|
||||
});
|
||||
}());
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
Reference in New Issue
Block a user