Skip to content
Open
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
19 changes: 15 additions & 4 deletions lib/tools/Config.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,15 +188,26 @@ Config._valid = function(key, value, sch){
}

// Verify maximum / minimum of Number value.
if (type == '[object Number]') {
if (this._error(typeof sch.max != 'undefined' && value > sch.max, 'max', key, sch.max, value)) {
if (type === '[object String]' && sch.regex) {

// Preventing heavy RegExp from ReDoS attack.
if (value.length > 1024) {
this._errors.push(`"${key}" exceeds maximum allowed length`);
return null;
}
if (this._error(typeof sch.min != 'undefined' && value < sch.min, 'min', key, sch.min, value)) {

let regex;
try {
regex = sch._compiledRegex || (sch._compiledRegex = new RegExp(sch.regex));
} catch (err) {
this._errors.push(`Invalid regex for "${key}"`);
return null;
}
}

if (!regex.test(value)) {
return null;
}
}
// If first type is Array, but current is String, try to split them.
if(scht.length > 1 && type != scht[0] && type == '[object String]'){
if(scht[0] == '[object Array]') {
Expand Down