Skip to content

Commit 2bec998

Browse files
committed
guard against polluting __proto__ in nestedProperty
1 parent 5efd2a1 commit 2bec998

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

Diff for: src/lib/nested_property.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,20 @@ module.exports = function nestedProperty(container, propStr) {
2424
throw 'bad property string';
2525
}
2626

27-
var j = 0;
2827
var propParts = propStr.split('.');
2928
var indexed;
3029
var indices;
31-
var i;
30+
var i, j;
31+
32+
for(j = 0; j < propParts.length; j++) {
33+
// guard against polluting __proto__ and other internals
34+
if(String(propParts[j]).slice(0, 2) === '__') {
35+
throw 'bad property string';
36+
}
37+
}
3238

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

0 commit comments

Comments
 (0)