Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
fix(commons): skip prototype-polluting keys in _.merge
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.

Same remediation as dove #3690 / @feathersjs/commons@5.0.45
(GHSA-28xv-ph75-77wh / CVE-2026-54335).

Reported-by: Andrew Ridings (@ridingsa)
  • Loading branch information
marshallswain committed Aug 10, 2026
commit e6abffce9829893292cf901d0c7902a56cfcd18b
5 changes: 5 additions & 0 deletions packages/commons/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ export const _ = {
merge (target: any, source: any) {
if (_.isObject(target) && _.isObject(source)) {
Object.keys(source).forEach(key => {
// Skip prototype-polluting keys (e.g. JSON-parsed `__proto__`)
if (key === '__proto__' || key === 'constructor' || key === 'prototype') {
return;
}

if (_.isObject(source[key])) {
if (!target[key]) {
Object.assign(target, { [key]: {} });
Expand Down
9 changes: 9 additions & 0 deletions packages/commons/test/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,15 @@ describe('@feathersjs/commons utils', () => {

assert.equal(_.merge('hello', {}), 'hello');
});

it('merge does not pollute Object.prototype', () => {
_.merge({}, JSON.parse('{"__proto__":{"polluted":"x"}}'));
_.merge({}, JSON.parse('{"constructor":{"prototype":{"polluted2":"y"}}}'));
assert.strictEqual(({} as any).polluted, undefined);
assert.strictEqual(({} as any).polluted2, undefined);
assert.strictEqual((Object.prototype as any).polluted, undefined);
assert.strictEqual((Object.prototype as any).polluted2, undefined);
});
});

describe('makeUrl', function () {
Expand Down
Loading