Skip to content

Commit c84fe82

Browse files
authored
fix(zipObjectDeep): prototype pollution (#4759)
1 parent e7b28ea commit c84fe82

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

lodash.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3990,6 +3990,10 @@
39903990
var key = toKey(path[index]),
39913991
newValue = value;
39923992

3993+
if (key === '__proto__' || key === 'constructor' || key === 'prototype') {
3994+
return object;
3995+
}
3996+
39933997
if (index != lastIndex) {
39943998
var objValue = nested[key];
39953999
newValue = customizer ? customizer(objValue, key, nested) : undefined;

test/test.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25799,6 +25799,39 @@
2579925799
});
2580025800
});
2580125801

25802+
// zipObjectDeep prototype pollution
25803+
['__proto__', 'constructor', 'prototype'].forEach(function (keyToTest) {
25804+
QUnit.test('zipObjectDeep is not setting ' + keyToTest + ' on global', function (assert) {
25805+
assert.expect(1);
25806+
25807+
_.zipObjectDeep([keyToTest + '.a'], ['newValue']);
25808+
// Can't access plain `a` as it's not defined and test fails
25809+
assert.notEqual(root['a'], 'newValue');
25810+
});
25811+
25812+
QUnit.test('zipObjectDeep is not overwriting ' + keyToTest + ' on vars', function (assert) {
25813+
assert.expect(3);
25814+
25815+
const b = 'oldValue'
25816+
_.zipObjectDeep([keyToTest + '.b'], ['newValue']);
25817+
assert.equal(b, 'oldValue');
25818+
assert.notEqual(root['b'], 'newValue');
25819+
25820+
// ensure nothing was created
25821+
assert.notOk(root['b']);
25822+
});
25823+
25824+
QUnit.test('zipObjectDeep is not overwriting global.' + keyToTest, function (assert) {
25825+
assert.expect(2);
25826+
25827+
_.zipObjectDeep([root + '.' + keyToTest + '.c'], ['newValue']);
25828+
assert.notEqual(root['c'], 'newValue');
25829+
25830+
// ensure nothing was created
25831+
assert.notOk(root['c']);
25832+
});
25833+
});
25834+
2580225835
/*--------------------------------------------------------------------------*/
2580325836

2580425837
QUnit.module('lodash.zipWith');

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy