Skip to content

fix(feathers): skip prototype-polluting keys in _.merge#3689

Merged
marshallswain merged 1 commit into
v6from
fix/commons-merge-proto-pollution
Jun 4, 2026
Merged

fix(feathers): skip prototype-polluting keys in _.merge#3689
marshallswain merged 1 commit into
v6from
fix/commons-merge-proto-pollution

Conversation

@marshallswain
Copy link
Copy Markdown
Member

@marshallswain marshallswain commented Jun 4, 2026

Summary

The recursive _.merge helper in packages/feathers/src/commons.ts iterates Object.keys(source). When the source object came from JSON.parse('{"__proto__":...}'), __proto__ is returned as an own-enumerable key (unlike the object-literal form), so the recursive call resolves target['__proto__'] to Object.prototype and writes onto it.

This adds the standard guard to skip __proto__, constructor, and prototype keys during iteration — the same remediation lodash applies in baseSet.

Changes

  • commons.ts: skip the three prototype-mutating keys in the merge loop.
  • commons.test.ts: regression test confirming a JSON-parsed __proto__/constructor.prototype source no longer mutates Object.prototype, fresh objects, or the target.

Notes

Reported-by: Andrew Ridings (@ridingsa)

Object.keys() returns __proto__ as an own enumerable key for
JSON-parsed sources, causing the recursive merge to write onto
Object.prototype. Skip __proto__/constructor/prototype keys.

Reported-by: Andrew Ridings (@ridingsa)
@marshallswain marshallswain force-pushed the fix/commons-merge-proto-pollution branch from 2d1c2f9 to 970e3f7 Compare June 4, 2026 01:54
@marshallswain marshallswain merged commit 836ce6d into v6 Jun 4, 2026
4 checks passed
@marshallswain marshallswain deleted the fix/commons-merge-proto-pollution branch June 4, 2026 02:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant