Node.js · Senior · Question 11 of 75
What is a typical cause of a slow regular expression blocking a Node.js server (ReDoS)?
/^(a+)+$/.test("aaaaaaaaaaaaaaaaaaaaaaaaaaaa!");- 1Regular expressions always run on the thread pool and exhaust it
- 2The
testmethod is deprecated - ✓Correct answer: Nested quantifiers cause catastrophic backtracking, so matching takes exponential time on certain inputs
Explanation
Since the regex runs on the main thread, one request can freeze the whole server. Avoid nested quantifiers, limit input length, or use a linear-time engine like RE2.