]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
[bugfix] Fix redos in preprocessRFC2822 regex (#6015)
authorKhang Vo (doublevkay) <45411113+vovikhangcdv@users.noreply.github.com>
Wed, 6 Jul 2022 15:28:25 +0000 (22:28 +0700)
committerIskren Chernev <me@iskren.info>
Wed, 6 Jul 2022 15:54:32 +0000 (18:54 +0300)
* fix ReDoS in preprocessRFC2822 regex

Fixes: [#2936](https://github.com/moment/moment/issues/6012)
Disallow nested rfc2822 comments to prevent quadratic regex execution time (i.e each open bracket is considered at most twice).

src/lib/create/from-string.js

index 5c4d11f7406fbcb80918868b7bd6ad5981dfbec2..58739b9d7c6e49936a18808bee7b25f39bcd9dc3 100644 (file)
@@ -151,7 +151,7 @@ function untruncateYear(yearStr) {
 function preprocessRFC2822(s) {
     // Remove comments and folding whitespace and replace multiple-spaces with a single space
     return s
-        .replace(/\([^)]*\)|[\n\t]/g, ' ')
+        .replace(/\([^()]*\)|[\n\t]/g, ' ')
         .replace(/(\s\s+)/g, ' ')
         .replace(/^\s\s*/, '')
         .replace(/\s\s*$/, '');