From ff66e26af0a59d3f63e7daf104a132f49f65879d Mon Sep 17 00:00:00 2001 From: Dorian Niemiec Date: Tue, 27 Aug 2024 12:06:23 +0200 Subject: [PATCH] Change regular expression for createRegex() function --- src/utils/createRegex.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/utils/createRegex.js b/src/utils/createRegex.js index 987f8a0..c18cfd9 100644 --- a/src/utils/createRegex.js +++ b/src/utils/createRegex.js @@ -1,7 +1,11 @@ const os = require("os"); function createRegex(regex, isPath) { - const regexStrMatch = regex.match(/^\/((?:\\.|[^/\\])*)\/([a-zA-Z0-9]*)$/); + // The new regular expression supports single unescaped "/" within [], but not two unescaped "/". + // We needed to do it, because it's very hard to create the regex that matches two unescaped "/" within "[]" without ReDoS. + const regexStrMatch = regex.match( + /^\/((?:\\.|\/+(?:(?:\\.|[^\]\\/])*\])|[^/\\])*)\/([a-zA-Z0-9]*)$/, + ); if (!regexStrMatch) throw new Error("Invalid regular expression: " + regex); const searchString = regexStrMatch[1]; let modifiers = regexStrMatch[2];