diff --git a/index.js b/index.js --- a/index.js +++ b/index.js @@ -44,6 +44,10 @@ function propertyIsOnObject(object, property) { } } +function propertyIsForbidden(key) { + return key === '__proto__' +} + // Protects from prototype poisoning and unexpected merging up the prototype chain. function propertyIsUnsafe(target, key) { return propertyIsOnObject(target, key) // Properties are safe to merge if they don't exist in the target yet, @@ -55,11 +59,14 @@ function mergeObject(target, source, options) { var destination = {} if (options.isMergeableObject(target)) { getKeys(target).forEach(function(key) { + if (propertyIsForbidden(key)) { + return + } destination[key] = cloneUnlessOtherwiseSpecified(target[key], options) }) } getKeys(source).forEach(function(key) { - if (propertyIsUnsafe(target, key)) { + if (propertyIsForbidden(key) || propertyIsUnsafe(target, key)) { return } diff --git a/dist/cjs.js b/dist/cjs.js --- a/dist/cjs.js +++ b/dist/cjs.js @@ -69,6 +69,10 @@ function propertyIsOnObject(object, property) { } } +function propertyIsForbidden(key) { + return key === '__proto__' +} + // Protects from prototype poisoning and unexpected merging up the prototype chain. function propertyIsUnsafe(target, key) { return propertyIsOnObject(target, key) // Properties are safe to merge if they don't exist in the target yet, @@ -80,11 +84,14 @@ function mergeObject(target, source, options) { var destination = {}; if (options.isMergeableObject(target)) { getKeys(target).forEach(function(key) { + if (propertyIsForbidden(key)) { + return + } destination[key] = cloneUnlessOtherwiseSpecified(target[key], options); }); } getKeys(source).forEach(function(key) { - if (propertyIsUnsafe(target, key)) { + if (propertyIsForbidden(key) || propertyIsUnsafe(target, key)) { return } diff --git a/dist/umd.js b/dist/umd.js --- a/dist/umd.js +++ b/dist/umd.js @@ -75,6 +75,10 @@ } } + function propertyIsForbidden(key) { + return key === '__proto__' + } + // Protects from prototype poisoning and unexpected merging up the prototype chain. function propertyIsUnsafe(target, key) { return propertyIsOnObject(target, key) // Properties are safe to merge if they don't exist in the target yet, @@ -86,11 +90,14 @@ var destination = {}; if (options.isMergeableObject(target)) { getKeys(target).forEach(function(key) { + if (propertyIsForbidden(key)) { + return + } destination[key] = cloneUnlessOtherwiseSpecified(target[key], options); }); } getKeys(source).forEach(function(key) { - if (propertyIsUnsafe(target, key)) { + if (propertyIsForbidden(key) || propertyIsUnsafe(target, key)) { return }