Dangers of Regular Expressions in JavaScript | Sonar
A deep investigation into regular expression denial of service (ReDoS) vulnerabilities in JavaScript
Backtracking
It might not seem obvious, but most problems with regular expressions stem from failing to match part of the string they are being evaluated against. Matching is easy, but not matching can cause a process called backtracking where the regular expression engine will go back over choices that it made and try alternatives.
Lost in spaces
Let's have a look at an example. In the Stack Overflow outage, the offending regular expression was /^[\s\u200c]+|[\s\u200c]+$/. Let's break down what each part means:
October 24, 2023 at 11:13:02 AM EDT
*
FILLER