A regular expression takes quadratic or higher polynomial time on some inputs, confirmed with an input that shows it

tx0/ts:regex-polynomial-backtrackingallnoteperformance/regexdepth fastperformance, security, cwe-1333

What it finds

/\s+$/.test(line): each start position runs the repetition to the end of the input before the anchor fails, so the time grows with the square of the input length, as in the outage of a large question-and-answer site in 2016. Reported as for regex-exponential-backtracking, when the confirmed growth is a polynomial of degree two or more.

From the rule's source, regex_backtracking.rs.

Example from the rule's tests
const a = /x\s*\s*$/;tx0 reports: quadratic timeconst b = /\s+$/;
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs from the all tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/ts:regex-polynomial-backtracking" = "note"

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/ts:regex-polynomial-backtracking] reason="..."

tx0 explain tx0/ts:regex-polynomial-backtracking shows the same in the terminal. Found a false positive? Report it.