Headline
CVE-2021-26707: add isValidKey function to ensure only valid keys are merged · jonschlinkert/merge-deep@11e5dd5
The merge-deep library before 3.0.3 for Node.js can be tricked into overwriting properties of Object.prototype or adding new properties to it. These properties are then inherited by every object in the program, thus facilitating prototype-pollution attacks against applications using this library.
@@ -32,7 +32,7 @@ module.exports = function mergeDeep(orig, objects) {
function merge(target, obj) {
for (var key in obj) {
if (key === ‘__proto__’ || !hasOwn(obj, key)) {
if (!isValidKey(key) || !hasOwn(obj, key)) {
continue;
}
@@ -57,3 +57,7 @@ function hasOwn(obj, key) {
function isObject(val) {
return typeOf(val) === ‘object’ || typeOf(val) === 'function’;
}
function isValidKey(key) {
return key !== ‘__proto__’ && key !== ‘constructor’ && key !== 'prototype’;
}