Skip to content

Commit

Permalink
skip assignment to __proto__
Browse files Browse the repository at this point in the history
  • Loading branch information
nlf authored and Marsup committed Feb 15, 2018
1 parent 1db691b commit 5aed1a8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/index.js
Expand Up @@ -113,6 +113,10 @@ exports.merge = function (target, source, isNullOverride /* = true */, isMergeAr
const keys = Object.keys(source);
for (let i = 0; i < keys.length; ++i) {
const key = keys[i];
if (key === '__proto__') {
continue;
}

const value = source[key];
if (value &&
typeof value === 'object') {
Expand Down
9 changes: 9 additions & 0 deletions test/index.js
Expand Up @@ -614,6 +614,15 @@ describe('merge()', () => {
expect(a.x.toString()).to.equal('abc');
done();
});

it('skips __proto__', () => {

const a = '{ "ok": "value", "__proto__": { "test": "value" } }';

const b = Hoek.merge({}, JSON.parse(a));
expect(b).to.equal({ ok: 'value' });
expect(b.test).to.equal(undefined);
});
});

describe('applyToDefaults()', () => {
Expand Down

0 comments on commit 5aed1a8

Please sign in to comment.