A JavaScript proposal to provide RegExp matching capabilities without the risk of catastrophic, unrecoverable failure.
Stage: 0
Champions: Michael Ficarra, Aurèle Barrière, Clément Pit-Claudel
Due to the use of a backtracking strategy in the RegExp engines embedded in all modern JavaScript engines, performing a RegExp match can be a dangerous operation. In these engines, depending on the pattern, the match operation may (practically) never complete, causing the program to enter an unrecoverable error state. Programs where this condition can be induced through user or environmental inputs are said to be vulnerable to ReDoS. ReDoS vulnerabilities have been highly prevalent in the JavaScript ecosystem for years. From January to May 2026, ReDoS vulnerabilities have resulted in a CVE every 2.7 days. Current mitigation strategies are often either too costly, too limiting, or inadequate.
We should provide solutions for the following use cases:
As this is an early stage proposal, the design space is still very open. But we have thought through some possible components of a solution that may be proposed at a later stage.
if (re.willMatchlinearly) {
re.exec(...);
} else {
// fallback behaviour
}
After constructing a RegExp, a predicate or other indicator (such as a RegExp.prototype getter) can be used to provide fallback behaviour if the engine is unable to match the pattern in linear time.
exec varianttry {
let match = re.execLinear(input);
} catch {
// fallback behaviour
}
A new RegExp.prototype method that is like exec but opts in to linear matching.
l flagtry {
let re = /pattern/l;
} catch {
// fallback behaviour
}
A new RegExp l flag could be used both to indicate to exec that a linear matching strategy is preferred as well as to throw on construction if the pattern cannot be matched linearly by the engine.
execlet match = re.exec(input, 10e3);
Some way for the programmer to communicate that a backtracking implementation should be used until some kind of resource exhaustion, at which point a linear implementation should be used. Alternatively, the operation could throw an error that indicates resource exhaustion and the programmer could provide the fallback behaviour.
Regexp.linear_time? predicateregex crate omits features with no known linear implementationRegexOptions.NonBacktracking opts a RegExp into a linear matching strategyregexp package omits features with no known linear implementation--enable-experimental-regexp-engineWhile it may sound appealing to limit worst-case complexity for all RegExps where it is possible to do so, this may actually have an unacceptable negative impact on most RegExp matches. Although backtracking implementations have very bad worst-case complexity, in typical cases, they will outperform linear implementations, especially newer, less-optimised linear implementations.