A regular expression that takes super-linear time is matched against request input

tx0/csharp:regex-backtracking-on-inputallerrorsecurity/denial-of-servicedepth fastbug, security, cwe-1333

What it finds

A pattern that takes exponential or polynomial time, as the two rules above find, matched against request input: Request.Query, Request.Form, Request.Headers, a parameter bound with [FromQuery], [FromBody] or the like, directly or through a local variable of the same method.

From the rule's source, regex_backtracking.rs.

Example from the rule's tests
using System.Text.RegularExpressions; public class Controller{    public bool Find([FromQuery] string q) => Regex.IsMatch(q, @"^(\w+\s?)*$");tx0 reports: request input from     public bool Local(string s) => Regex.IsMatch(s, @"^(\w+\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/csharp:regex-backtracking-on-input" = "error"

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/csharp:regex-backtracking-on-input] reason="..."

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