From 7aebb1617fc9bced87ab6bc4c317644019b23ce7 Mon Sep 17 00:00:00 2001 From: "Khang Vo (doublevkay)" <45411113+vovikhangcdv@users.noreply.github.com> Date: Wed, 6 Jul 2022 22:28:25 +0700 Subject: [PATCH] [bugfix] Fix redos in preprocessRFC2822 regex (#6015) * 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 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/create/from-string.js b/src/lib/create/from-string.js index 5c4d11f740..58739b9d7c 100644 --- a/src/lib/create/from-string.js +++ b/src/lib/create/from-string.js @@ -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*$/, '');