A regular expression takes exponential time on some inputs, confirmed with an input that shows it
What it finds
preg_match('/^(\w+\s?)*$/', $name): on an input that almost matches, such as a long run of letters followed by !, PCRE tries exponentially many ways to split the letters between the inner and the outer repetition. It stops at pcre.backtrack_limit or the stack limit of its compiled code, and the call then returns false, which reads as "no match", after burning the time up to the limit on every request (CWE-1333).
The pattern is turned into an automaton and searched for ambiguity: a state that reaches itself on one input along two paths makes the time exponential. Every candidate is then confirmed by running the input it suggests, as the preg_* functions search for the pattern (or match at the start with the A modifier), on a backtracking matcher that follows the pattern exactly, lookarounds, atomic groups and possessive quantifiers included. Patterns matched against request input are reported by regex-backtracking-on-input instead.
From the rule's source, regex_backtracking.rs.
<?phpfunction check($s){ $a = preg_match('/^(\w+\s?)*$/', $s);tx0 reports: exponential time $b = preg_match('/^(\w+\s?)*$/x', $s); $c = preg_match('/^(\S+\s+)*x$/', $s); $d = preg_match('/^(\w++\s?)*$/', $s); return $a;} Turn it on, off or suppress it
The rule runs in every tier. To turn it off for a project, set its level in tx0.toml:
[rules]
"tx0/php:regex-exponential-backtracking" = "off"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/php:regex-exponential-backtracking] reason="..."tx0 explain tx0/php:regex-exponential-backtracking shows the same in the terminal. Found a false positive? Report it.