Skip to content

Commit 94c9cf9

Browse files
committed
prototype pollution fix #2
1 parent 829f395 commit 94c9cf9

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

lib/processNested.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const INVALID_KEYS = ['__proto__'];
1+
const INVALID_KEYS = ['__proto__', 'constructor'];
22

33
module.exports = function(data){
44
if (!data || data.length < 1) return {};

test/processNested.spec.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,13 @@ describe('Test Convert Flatten object to Nested object', function() {
4747
});
4848

4949
it('Do not allow prototype pollution', () => {
50-
const pollutionOb = JSON.parse(`{"__proto__.POLLUTED": "FOOBAR"}`);
50+
const pollutionOb1 = JSON.parse(`{"__proto__.POLLUTED1": "FOOBAR"}`);
51+
const pollutionOb2 = JSON.parse(`{"constructor.prototype.POLLUTED2": "FOOBAR"}`);
5152

52-
processNested(pollutionOb);
53+
processNested(pollutionOb1);
54+
processNested(pollutionOb2);
5355

54-
// eslint-disable-next-line no-undef
55-
assert.equal(global.POLLUTED, undefined);
56+
assert.equal(global.POLLUTED1, undefined);
57+
assert.equal(global.POLLUTED2, undefined);
5658
});
5759
});

0 commit comments

Comments
 (0)