Skip to content

Security Fix for Regular Expression Denial of Service (ReDoS) - huntr.dev #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
20 changes: 10 additions & 10 deletions lib/time-span.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ var msecPerSecond = 1000,
//
// ### Timespan Parsers
//
var timeSpanWithDays = /^(\d+):(\d+):(\d+):(\d+)(\.\d+)?/,
timeSpanNoDays = /^(\d+):(\d+):(\d+)(\.\d+)?/;
var timeSpanWithDays = /^(\d{1,16}):(\d{1,16}):(\d{1,16}):(\d{1,16})(\.\d{1,16})?/,
timeSpanNoDays = /^(\d{1,16}):(\d{1,16}):(\d{1,16})(\.\d{1,16})?/;

//
// ### function TimeSpan (milliseconds, seconds, minutes, hours, days)
Expand Down Expand Up @@ -165,7 +165,7 @@ exports.parse = function (str) {
//
var parsers = {
'milliseconds': {
exp: /(\d+)milli(?:second)?[s]?/i,
exp: /(\d{1,16})milli(?:second)?[s]?/i,
compute: function (delta, computed) {
return _compute(delta, computed, {
current: 'milliseconds',
Expand All @@ -175,7 +175,7 @@ var parsers = {
}
},
'seconds': {
exp: /(\d+)second[s]?/i,
exp: /(\d{1,16})second[s]?/i,
compute: function (delta, computed) {
return _compute(delta, computed, {
current: 'seconds',
Expand All @@ -185,7 +185,7 @@ var parsers = {
}
},
'minutes': {
exp: /(\d+)minute[s]?/i,
exp: /(\d{1,16})minute[s]?/i,
compute: function (delta, computed) {
return _compute(delta, computed, {
current: 'minutes',
Expand All @@ -195,7 +195,7 @@ var parsers = {
}
},
'hours': {
exp: /(\d+)hour[s]?/i,
exp: /(\d{1,16})hour[s]?/i,
compute: function (delta, computed) {
return _compute(delta, computed, {
current: 'hours',
Expand All @@ -205,7 +205,7 @@ var parsers = {
}
},
'days': {
exp: /(\d+)day[s]?/i,
exp: /(\d{1,16})day[s]?/i,
compute: function (delta, computed) {
var days = monthDays(computed.months, computed.years),
sign = delta >= 0 ? 1 : -1,
Expand Down Expand Up @@ -249,7 +249,7 @@ var parsers = {
}
},
'months': {
exp: /(\d+)month[s]?/i,
exp: /(\d{1,16})month[s]?/i,
compute: function (delta, computed) {
var round = delta > 0 ? Math.floor : Math.ceil;
if (delta) {
Expand All @@ -266,7 +266,7 @@ var parsers = {
}
},
'years': {
exp: /(\d+)year[s]?/i,
exp: /(\d{1,16})year[s]?/i,
compute: function (delta, computed) {
if (delta) { computed.years += delta; }
return computed;
Expand Down Expand Up @@ -321,7 +321,7 @@ exports.parseDate = function (str) {
// of the target `str` to parse.
//
parserNames.forEach(function (group) {
zulu += '(\\d+[a-zA-Z]+)?';
zulu += '(\\d{1,16}[a-zA-Z]+)?';
});

if (/^NOW/i.test(str)) {
Expand Down