An unbounded repetition in a regular expression contains another one, which can backtrack exponentially
What it finds
/(a+)+$/, /(\w*)*x/, /(?:.*,)*end/: a repetition with no upper bound around a group that itself repeats without bound can match the same text in exponentially many ways. On an input that almost matches, the backtracking engine of JavaScript tries all of them, and a short string can block the event loop for minutes. Where the input comes from users, this is a denial of service.
Reported are *, + and {n,} applied to a group that contains, at any depth, another unbounded repetition. The pattern can usually be rewritten so that each part of the input can be matched in one way only.
From the rule's source, regex_nested_repetition.rs.
const a = /(a+)+$/;tx0 reports: a repeated group in this pattern contains another unbounded repetitionconst b = /^(?:\w*\s?)*$/;tx0 reports: a repeated group in this pattern contains another unbounded repetitionconst c = /(ab)+/;const d = /(a{1,3})+/;const e = /\d+(?:\.\d+)?/; Turn it on, off or suppress it
The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/ts:regex-nested-repetition" = "warning"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-nested-repetition] reason="..."tx0 explain tx0/ts:regex-nested-repetition shows the same in the terminal. Found a false positive? Report it.