Skip to content

Commit 847aa00

Browse files
author
taylorhakes
committed
Fixed possible regular expression denial of service
1 parent 04829ba commit 847aa00

File tree

5 files changed

+16
-3
lines changed

5 files changed

+16
-3
lines changed

bower.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "fecha",
33
"main": "fecha.js",
4-
"version": "1.1.1",
4+
"version": "1.2.0",
55
"homepage": "https://github.com/taylorhakes/fecha",
66
"authors": [
77
"Taylor Hakes"

fecha.js

+6
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,12 @@
208208

209209
format = fecha.masks[format] || format;
210210

211+
// Avoid regular expression denial of service, fail early for really long strings
212+
// https://www.owasp.org/index.php/Regular_expression_Denial_of_Service_-_ReDoS
213+
if (dateStr.length > 1000) {
214+
return false;
215+
}
216+
211217
isValid = true;
212218
dateInfo = {};
213219
format.replace(token, function ($0) {

fecha.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

fecha.spec.js

+7
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,13 @@
9696
fecha.parse('2014-11-05', false)
9797
}).toThrow();
9898
});
99+
it('long input false', function () {
100+
var input = '';
101+
for (var i = 0; i < 1002; i++) {
102+
input += '1';
103+
}
104+
expect(fecha.parse(input, 'HH')).toBe(false);
105+
});
99106
});
100107
describe('format', function () {
101108
// Day of the month

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "fecha",
3-
"version": "1.1.1",
3+
"version": "1.2.0",
44
"description": "Date formatting and parsing",
55
"main": "fecha.js",
66
"scripts": {

0 commit comments

Comments
 (0)