Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix: avoids prototype pollution
  • Loading branch information
kricsleo committed Apr 1, 2026
commit 70aa6044f5a762c9738eaf24d9667189cd78b611
2 changes: 1 addition & 1 deletion src/defu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function _defu<T>(
return _defu(baseObject, {}, namespace, merger);
}

const object = Object.assign({}, defaults);
const object = { ...defaults };

for (const key in baseObject) {
if (key === "__proto__" || key === "constructor") {
Expand Down
6 changes: 6 additions & 0 deletions test/defu.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ describe("defu", () => {
defu({}, payload);
defu(payload, {});
defu(payload, payload);

const malicious = JSON.parse('{"__proto__":{"isAdmin":true}}');
const result = defu(malicious, { isAdmin: false });

expect(result.isAdmin).toBe(false);

// @ts-ignore
expect({}.isAdmin).toBe(undefined);
});
Expand Down
Loading