From 5f756b4470d91778702cace5f5fce8060aeb7ad6 Mon Sep 17 00:00:00 2001 From: Kevin Backhouse Date: Thu, 8 Aug 2024 18:49:30 +0100 Subject: [PATCH] Fix ReDoS (#1980) * Simplify the regex to make it easier to fix the ReDoS. The new version isn't exactly equivalent to the old: it matches a superset of the strings matched by the old version. * Fix ReDoS --- lib/autoInject.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/autoInject.js b/lib/autoInject.js index b1f242e18..68eb3c99c 100644 --- a/lib/autoInject.js +++ b/lib/autoInject.js @@ -2,8 +2,8 @@ import auto from './auto.js' import wrapAsync from './internal/wrapAsync.js' import { isAsync } from './internal/wrapAsync.js' -var FN_ARGS = /^(?:async\s+)?(?:function)?\s*\w*\s*\(\s*([^)]+)\s*\)(?:\s*{)/; -var ARROW_FN_ARGS = /^(?:async\s+)?\(?\s*([^)=]+)\s*\)?(?:\s*=>)/; +var FN_ARGS = /^(?:async\s)?(?:function)?\s*(?:\w+\s*)?\(([^)]+)\)(?:\s*{)/; +var ARROW_FN_ARGS = /^(?:async\s)?\s*(?:\(\s*)?((?:[^)=\s]\s*)*)(?:\)\s*)?=>/; var FN_ARG_SPLIT = /,/; var FN_ARG = /(=.+)?(\s*)$/;