A regular expression that takes super-linear time is matched against request input
What it finds
A pattern that takes exponential or polynomial time, as the two rules above find, applied to request input: a parameter annotated as request data (@RequestParam, @PathVariable, @QueryParam and the like) or the result of getParameter, getHeader, getQueryString and the other readers of a servlet request, directly or through a local variable of the same method. The same readers called on a receiver named as a response read what a server sent back and are not counted.
From the rule's source, regex_backtracking.rs.
import java.util.regex.Pattern; class Controller { boolean a(@RequestParam String q) { return q.matches("((a|a)*)?b"); }tx0 reports: request input from q boolean b(javax.servlet.http.HttpServletRequest request) { String name = request.getParameter("name"); return name.matches("((a|a)*)?b");tx0 reports: request input } boolean c(String s) { return s.matches("((a|a)*)?b"); } boolean d(org.springframework.http.ResponseEntity<String> responseEntity) { return responseEntity.getHeaders().getFirst("X").matches("((a|a)*)?b"); }} 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:
[rules]
"tx0/java: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/java:regex-backtracking-on-input] reason="..."tx0 explain tx0/java:regex-backtracking-on-input shows the same in the terminal. Found a false positive? Report it.