bynk.types.catastrophic_regex
Error A Matches pattern, or a regex method's pattern, can match the same text in exponentially many ways (nested or ambiguous repetition, bounded or not), or cannot be analysed, risking catastrophic backtracking (ReDoS).
A Matches pattern, and the pattern of a regex method such as matchesRegex or replaceRegex, is analysed when the program compiles. Patterns run with JavaScript's backtracking RegExp, and one in which a repetition can split the same text several ways takes exponential time on a crafted near miss, so a few dozen characters of input could stall a handler. Nested or ambiguous repetition, such as (a+)+ or (a|aa)+, is refused, bounded or not, as is a backreference under an unbounded quantifier, an unbounded quantifier over a body that can match the empty string, and a pattern too large or complex to analyse. Rewrite it so each repetition has one way to match: a+ for (a+)+, or a separator the repeated part cannot match, as in [a-z]+(-[a-z]+)*. Two adjacent repetitions that compete, as in \d*\d*, are the milder bynk.types.polynomial_regex.
Example
type Code = String where Matches("(a+)+$") // ✗ nested unbounded repetition
type Code = String where Matches("a+$") // ✓ one way to matchIn the Book
See also
- The grammar rule it governs:
refinement. - Every code in its category, Type checking, on the diagnostic index.
bynk explain bynk.types.catastrophic_regexshows the same from the installed toolchain, without a network.