Before embedding user input into a regular expression, use a sanitization function
-to escape meta-characters that have special meaning.
+such as Pattern.quote
to escape meta-characters that have special meaning.
-The following example shows a HTTP request parameter that is used to construct a regular expression: +The following example shows an HTTP request parameter that is used to construct a regular expression.
-In the first case the user-provided regex is not escaped. -If a malicious user provides a regex that has exponential worst case performance, +If a malicious user provides a regex whose worst-case performance is exponential, then this could lead to a Denial of Service.
-In the second case, the user input is escaped using escapeSpecialRegexChars
before being included
+In the second case, the user input is escaped using Pattern.quote
before being included
in the regular expression. This ensures that the user cannot insert characters which have a special
meaning in regular expressions.