Skip to content

Commit 4d0804b

Browse files
committed
Backport #352. Closes #353
1 parent 4ae5f53 commit 4d0804b

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

lib/clone.js

+4
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ module.exports = internals.clone = function (obj, options = {}, _seen = null) {
7575

7676
const keys = Utils.keys(obj, options);
7777
for (const key of keys) {
78+
if (key === '__proto__') {
79+
continue;
80+
}
81+
7882
if (baseProto === Types.array &&
7983
key === 'length') {
8084

test/index.js

+9
Original file line numberDiff line numberDiff line change
@@ -762,6 +762,15 @@ describe('clone()', () => {
762762
expect(copy.a).to.shallow.equal(obj.a);
763763
expect(copy.x).to.shallow.equal(obj);
764764
});
765+
766+
it('prevents prototype poisoning', () => {
767+
768+
const a = JSON.parse('{ "__proto__": { "x": 1 } }');
769+
expect(a.x).to.not.exist();
770+
771+
const b = Hoek.clone(a);
772+
expect(b.x).to.not.exist();
773+
});
765774
});
766775

767776
describe('merge()', () => {

0 commit comments

Comments
 (0)