Skip to content

Commit

Permalink
Prevent prototype poisoning in clone(). Closes #352
Browse files Browse the repository at this point in the history
  • Loading branch information
hueniverse committed Feb 8, 2020
1 parent 0ab1b4f commit 948baf9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 4 additions & 0 deletions lib/clone.js
Expand Up @@ -77,6 +77,10 @@ module.exports = internals.clone = function (obj, options = {}, _seen = null) {

const keys = Utils.keys(obj, options);
for (const key of keys) {
if (key === '__proto__') {
continue;
}

if (baseProto === Types.array &&
key === 'length') {

Expand Down
2 changes: 1 addition & 1 deletion test/clone.js
Expand Up @@ -818,7 +818,7 @@ describe('clone()', () => {

it('prevents prototype poisoning', () => {

const a = JSON.parse('{ "proto": { "x": 1 } }');
const a = JSON.parse('{ "__proto__": { "x": 1 } }');
expect(a.x).to.not.exist();

const b = Hoek.clone(a);
Expand Down

0 comments on commit 948baf9

Please sign in to comment.