chore(vulnerability): Inefficient Regular Expression - Potential high time complexity leading to ReDoS #10315
+1
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
const URLPattern = new RegExp(/^(?:http(s)?://)?[\w.-]+(?:.
[\w.-]+
)+[\w-._~:/?#[]@!$&'()*+,;=.]+$/);This part of the regular expression may cause exponential backtracking on strings starting with '-.' and containing many repetitions of '-.'.
References of the Vulnerability and Weaknesses
The current expression
[\w.-]+
matches any combination of word characters which could potentially lead to inefficient matching, especially on large input strings.The proposed fix limits the characters to letters (both upper and lowercase), digits, dots, and hyphens which are typically valid characters for domain extensions.
Also, minimum of 2 characters has been set to ensure a valid domain extension, such as ".com" or ".co.in" or ".org" etc.