Click to see the query in the CodeQL repository
Constructing a regular expression with unsanitized user input is dangerous, since a malicious user may be able to modify the meaning of the expression. In particular, such a user may be able to provide a regular expression fragment that takes exponential time in the worst case, and use that to perform a Denial of Service attack.
Before embedding user input into a regular expression, use a sanitization function such as Regexp.escape to escape meta-characters that have special meaning.
The following examples construct regular expressions from an HTTP request parameter without sanitizing it first:
Instead, the request parameter should be sanitized first. This ensures that the user cannot insert characters that have special meanings in regular expressions.
Wikipedia: ReDoS.
Ruby: Regexp.escape.
Common Weakness Enumeration: CWE-1333.
Common Weakness Enumeration: CWE-730.
Common Weakness Enumeration: CWE-400.