Skip to content

Commit

Permalink
guard against polluting __proto__ in nestedProperty
Browse files Browse the repository at this point in the history
  • Loading branch information
archmoj committed Aug 11, 2023
1 parent 5efd2a1 commit 2bec998
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/lib/nested_property.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,20 @@ module.exports = function nestedProperty(container, propStr) {
throw 'bad property string';
}

var j = 0;
var propParts = propStr.split('.');
var indexed;
var indices;
var i;
var i, j;

for(j = 0; j < propParts.length; j++) {
// guard against polluting __proto__ and other internals
if(String(propParts[j]).slice(0, 2) === '__') {
throw 'bad property string';
}
}

// check for parts of the nesting hierarchy that are numbers (ie array elements)
j = 0;
while(j < propParts.length) {
// look for non-bracket chars, then any number of [##] blocks
indexed = String(propParts[j]).match(/^([^\[\]]*)((\[\-?[0-9]*\])+)$/);
Expand Down

0 comments on commit 2bec998

Please sign in to comment.