Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zipObjectDeep: fix prototype pollution #4759

Merged
merged 1 commit into from Jul 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions lodash.js
Expand Up @@ -3990,6 +3990,10 @@
var key = toKey(path[index]),
newValue = value;

if (key === '__proto__' || key === 'constructor' || key === 'prototype') {
return object;
}

if (index != lastIndex) {
var objValue = nested[key];
newValue = customizer ? customizer(objValue, key, nested) : undefined;
Expand Down
33 changes: 33 additions & 0 deletions test/test.js
Expand Up @@ -25787,6 +25787,39 @@
});
});

// zipObjectDeep prototype pollution
['__proto__', 'constructor', 'prototype'].forEach(function (keyToTest) {
QUnit.test('zipObjectDeep is not setting ' + keyToTest + ' on global', function (assert) {
assert.expect(1);

_.zipObjectDeep([keyToTest + '.a'], ['newValue']);
// Can't access plain `a` as it's not defined and test fails
assert.notEqual(root['a'], 'newValue');
});

QUnit.test('zipObjectDeep is not overwriting ' + keyToTest + ' on vars', function (assert) {
assert.expect(3);

const b = 'oldValue'
_.zipObjectDeep([keyToTest + '.b'], ['newValue']);
assert.equal(b, 'oldValue');
assert.notEqual(root['b'], 'newValue');

// ensure nothing was created
assert.notOk(root['b']);
});

QUnit.test('zipObjectDeep is not overwriting global.' + keyToTest, function (assert) {
assert.expect(2);

_.zipObjectDeep([root + '.' + keyToTest + '.c'], ['newValue']);
assert.notEqual(root['c'], 'newValue');

// ensure nothing was created
assert.notOk(root['c']);
});
});

/*--------------------------------------------------------------------------*/

QUnit.module('lodash.zipWith');
Expand Down