Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
4 changes: 3 additions & 1 deletion test/jasmine/tests/lib_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,9 @@ describe('Test lib.js:', function() {

it('should fail on a bad property string', function() {
var badStr = [
[], {}, false, undefined, null, NaN, Infinity
[], {}, false, undefined, null, NaN, Infinity,
// should guard against prototype pollution
'x.__proto__.polluted', 'x.y.__proto__.polluted'
];

function badProp(i) {
Expand Down