From dc0d180e90d8a84f7ff13572363330a22b3ea504 Mon Sep 17 00:00:00 2001 From: "Khang Vo (doublevkay)" <45411113+vovikhangcdv@users.noreply.github.com> Date: Tue, 7 Jun 2022 13:39:39 +0700 Subject: [PATCH] fix redos in preprocessRFC2822 regex Fixes: [#2936](https://github.com/moment/moment/issues/6012) Directly match the comment tokens in preprocessRFC2822 regex to resolve the problem [Regular Expression Denial of Service (ReDoS)#6012](https://github.com/moment/moment/issues/6012) --- 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..c1be6f8338 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(/\([a-zA-Z0-9\s]*\)|[\n\t]/g, ' ') .replace(/(\s\s+)/g, ' ') .replace(/^\s\s*/, '') .replace(/\s\s*$/, '');