Skip to content

Commit

Permalink
fix: prototype pollution in several npm packages (#4337)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kirill89 authored and jdalton committed Jun 24, 2019
1 parent f2f9517 commit bb2e678
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
24 changes: 22 additions & 2 deletions lodash.defaultsdeep/index.js
Expand Up @@ -1130,6 +1130,26 @@ function baseMerge(object, source, srcIndex, customizer, stack) {
});
}

/**
* Gets the value at `key`, unless `key` is "__proto__" or "constructor".
*
* @private
* @param {Object} object The object to query.
* @param {string} key The key of the property to get.
* @returns {*} Returns the property value.
*/
function safeGet(object, key) {
if (key === 'constructor' && typeof object[key] === 'function') {
return;
}

if (key == '__proto__') {
return;
}

return object[key];
}

/**
* A specialized version of `baseMerge` for arrays and objects which performs
* deep merges and tracks traversed objects enabling objects with circular
Expand All @@ -1146,8 +1166,8 @@ function baseMerge(object, source, srcIndex, customizer, stack) {
* counterparts.
*/
function baseMergeDeep(object, source, key, srcIndex, mergeFunc, customizer, stack) {
var objValue = object[key],
srcValue = source[key],
var objValue = safeGet(object, key),
srcValue = safeGet(source, key),
stacked = stack.get(srcValue);

if (stacked) {
Expand Down
2 changes: 1 addition & 1 deletion lodash.merge/index.js
Expand Up @@ -1001,7 +1001,7 @@ function baseMergeDeep(object, source, key, srcIndex, mergeFunc, customizer, sta
if (isArguments(objValue)) {
newValue = toPlainObject(objValue);
}
else if (!isObject(objValue) || (srcIndex && isFunction(objValue))) {
else if (!isObject(objValue) || isFunction(objValue)) {
newValue = initCloneObject(srcValue);
}
}
Expand Down
2 changes: 1 addition & 1 deletion lodash.mergewith/index.js
Expand Up @@ -1001,7 +1001,7 @@ function baseMergeDeep(object, source, key, srcIndex, mergeFunc, customizer, sta
if (isArguments(objValue)) {
newValue = toPlainObject(objValue);
}
else if (!isObject(objValue) || (srcIndex && isFunction(objValue))) {
else if (!isObject(objValue) || isFunction(objValue)) {
newValue = initCloneObject(srcValue);
}
}
Expand Down

0 comments on commit bb2e678

Please sign in to comment.