Skip to content

Commit 0249840

Browse files
authored
Merge pull request #6704 from plotly/nestedProperty-proto
Fix potential prototype pollution in `nestedProperty`
2 parents a860a32 + 5cfbd6e commit 0249840

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
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]*\])+)$/);

Diff for: test/jasmine/tests/lib_test.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,9 @@ describe('Test lib.js:', function() {
468468

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

474476
function badProp(i) {

0 commit comments

Comments
 (0)