Skip to content

Commit db49535

Browse files
Merge pull request #237 from richardgirges/fix-236-proto-pollution
Fix prototype pollution issue in `processNested`
2 parents e9848fc + d81bee9 commit db49535

4 files changed

Lines changed: 518 additions & 503 deletions

File tree

lib/processNested.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
const INVALID_KEYS = ['__proto__'];
2+
13
module.exports = function(data){
24
if (!data || data.length < 1) return {};
35

@@ -11,10 +13,16 @@ module.exports = function(data){
1113
keyParts = key
1214
.replace(new RegExp(/\[/g), '.')
1315
.replace(new RegExp(/\]/g), '')
14-
.split('.');
15-
16+
.split('.');
17+
1618
for (let index = 0; index < keyParts.length; index++){
1719
let k = keyParts[index];
20+
21+
// Ensure we don't allow prototype pollution
22+
if (INVALID_KEYS.includes(k)) {
23+
continue;
24+
}
25+
1826
if (index >= keyParts.length - 1){
1927
current[k] = value;
2028
} else {

0 commit comments

Comments
 (0)