Unsanitized User Input in Regular Expression
Last updated
Last updated
Rule ID: java_lang_regex_using_user_input
Applicable Languages: Java
Weakness ID: CWE-1287
Building regular expressions from user input can result in a vulnerability called Regular Expression Denial of Service (ReDoS). This occurs because some regular expressions can have exponential time complexity. If attackers exploit this, they can trigger significant CPU usage spikes, thereby denying service to legitimate users.
Avoid using user input directly in regular expressions whenever possible to prevent attackers from exploiting complex patterns that cause excessive CPU consumption.
If user input must be used in a regular expression, sanitize or validate it to ensure it does not contain patterns that could lead to ReDoS.
To omit this rule during a scan, and to provide you with continuous 24/7 code-level scanning, you can employ our