Skip to content

Commit

Permalink
fix(util): fix prototype pollution vulnerability in utilities
Browse files Browse the repository at this point in the history
  • Loading branch information
plainheart committed Dec 6, 2024
1 parent 3e6cdda commit 6e687ee
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/core/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ var nativeFilter = arrayProto.filter;
var nativeSlice = arrayProto.slice;
var nativeMap = arrayProto.map;
var nativeReduce = arrayProto.reduce;
var protoKey = '__proto__';

// Avoid assign to an exported variable, for transforming to cjs.
var methods = {};
Expand Down Expand Up @@ -97,7 +98,7 @@ export function clone(source) {
else if (!BUILTIN_OBJECT[typeStr] && !isPrimitive(source) && !isDom(source)) {
result = {};
for (var key in source) {
if (source.hasOwnProperty(key)) {
if (source.hasOwnProperty(key) && key !== protoKey) {
result[key] = clone(source[key]);
}
}
Expand All @@ -120,7 +121,7 @@ export function merge(target, source, overwrite) {
}

for (var key in source) {
if (source.hasOwnProperty(key)) {
if (source.hasOwnProperty(key) && key !== protoKey) {
var targetProp = target[key];
var sourceProp = source[key];

Expand Down Expand Up @@ -169,7 +170,7 @@ export function mergeAll(targetAndSources, overwrite) {
*/
export function extend(target, source) {
for (var key in source) {
if (source.hasOwnProperty(key)) {
if (source.hasOwnProperty(key) && key !== protoKey) {
target[key] = source[key];
}
}
Expand All @@ -184,7 +185,7 @@ export function extend(target, source) {
*/
export function defaults(target, source, overlay) {
for (var key in source) {
if (source.hasOwnProperty(key)
if (source.hasOwnProperty(key) && key !== protoKey
&& (overlay ? source[key] != null : target[key] == null)
) {
target[key] = source[key];
Expand Down

0 comments on commit 6e687ee

Please sign in to comment.