Skip to content

Commit

Permalink
fix(utils): fix prototype attack for merge
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Apr 11, 2024
1 parent e83e6bd commit 985ca8e
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/utils/src/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@ export function defineEnumProperty<T extends object>(object: T, key: keyof T, va

export function merge<T extends object>(head: T, base: T): T {
Object.entries(base).forEach(([key, value]) => {
if (typeof head[key] === 'undefined') return head[key] = base[key]
if (typeof head[key] === 'undefined') return head[key] = value
// prevent prototype attack
if (!Object.hasOwn(head, key)) return
if (typeof value === 'object' && typeof head[key] === 'object') {
head[key] = merge(head[key], value)
} else {
head[key] = value
}
})
return head
Expand Down

0 comments on commit 985ca8e

Please sign in to comment.