@@ -50,6 +50,8 @@ function mergeRecursively<T1, T2>(
5050 const symbols = Object . getOwnPropertySymbols ( origin )
5151 newObject = [ ...props , ...symbols ] . reduce (
5252 ( carry , key ) => {
53+ // Skip __proto__ properties to prevent prototype poisoning
54+ if ( key === '__proto__' ) return carry
5355 const targetVal = origin [ key as string ]
5456 if (
5557 ( ! isSymbol ( key ) && ! Object . getOwnPropertyNames ( newComer ) . includes ( key ) ) ||
@@ -71,6 +73,8 @@ function mergeRecursively<T1, T2>(
7173 const props = Object . getOwnPropertyNames ( newComer )
7274 const symbols = Object . getOwnPropertySymbols ( newComer )
7375 const result = [ ...props , ...symbols ] . reduce ( ( carry , key ) => {
76+ // Skip __proto__ properties to prevent prototype poisoning
77+ if ( key === '__proto__' ) return carry
7478 // re-define the origin and newComer as targetVal and newVal
7579 let newVal = newComer [ key as string ]
7680 const targetVal = isPlainObject ( origin ) ? origin [ key as string ] : undefined
@@ -91,9 +95,8 @@ function mergeRecursively<T1, T2>(
9195}
9296
9397/**
94- * Merge anything recursively.
95- * Objects get merged, special objects (classes etc.) are re-assigned "as is".
96- * Basic types overwrite objects or other basic types.
98+ * Merge anything recursively. Objects get merged, special objects (classes etc.) are re-assigned
99+ * "as is". Basic types overwrite objects or other basic types.
97100 */
98101export function merge < T , const Tn extends unknown [ ] > ( object : T , ...otherObjects : Tn ) : Merge < T , Tn > {
99102 return otherObjects . reduce ( ( result , newComer ) => {
0 commit comments