Skip to content

Commit eff7778

Browse files
authored
Merge pull request #181 from dli7319/options
Prevent prototype pollution in options merging.
2 parents 0ef19ca + 91d4127 commit eff7778

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/utils/OptionsUtils.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,14 @@ export function deepMerge<T extends object, U extends object>(
4040
const merged = obj1 as Record<string, unknown>;
4141

4242
for (const key in obj2) {
43-
// Ensure the key is actually on obj2, not its prototype chain.
44-
if (Object.prototype.hasOwnProperty.call(obj2, key)) {
43+
// Ensure the key is actually on obj2, not its prototype chain,
44+
// and skip dangerous keys to prevent prototype pollution.
45+
if (
46+
Object.hasOwn(obj2, key) &&
47+
key !== '__proto__' &&
48+
key !== 'constructor' &&
49+
key !== 'prototype'
50+
) {
4551
const val1 = merged[key];
4652
const val2 = obj2[key];
4753

0 commit comments

Comments
 (0)