Merge pull request #8949 from sebakerckhof/fix/ejsondos

Cut of regex flags in ejson parser to avoid abuse
This commit is contained in:
Jesse Rosenberger
2017-07-27 19:40:00 +03:00
committed by GitHub

View File

@@ -105,8 +105,11 @@ var builtinConverters = [
return { $regexp: regexp.source, $flags: regexp.flags };
},
fromJSONValue: function (obj) {
//replaces duplicate / invalid flags
return new RegExp(obj.$regexp, obj.$flags.replace(/[^gimuy]/g,'').replace(/(.)(?=.*\1)/g, ''));
// replaces duplicate / invalid flags
// cut of flags to 50 chars to avoid abusing regex for DOS
return new RegExp(obj.$regexp, obj.$flags.substr(0, 50)
.replace(/[^gimuy]/g,'')
.replace(/(.)(?=.*\1)/g, ''));
}
},
{ // NaN, Inf, -Inf. (These are the only objects with typeof !== 'object'