· via dev.to (home feed)
How one regex with nested quantifiers can freeze a Node.js event loop
A dev.to post explains how nested quantifiers like ([a-z0-9._-]+)+ trigger exponential backtracking in V8, letting a single 35-byte request stall a Node.js server for all concurrent users.

A 35-byte request that takes the server down
A post on dev.to by dev_in_the_fog explains how a regular expression pasted in from a snippet collection can push a Node.js API server to sustained 100% CPU usage from a single small request — around 35 bytes. The culprit is a failure mode known as ReDoS, short for Regular Expression Denial of Service, and it follows from how V8, the JavaScript engine Node.js runs on, executes patterns: as a backtracking NFA that works through alternatives one by one.
Why the unit tests stay green
The article's centerpiece is a poorly structured email validator. The local part of the address is matched by a character class covering letters, digits, dots, underscores and hyphens — but that class is quantified twice: once with a + inside a group, then again on the group itself, producing the shape ([a-zA-Z0-9._-]+)+.
According to the post, the asymmetry that makes this bug hard to catch is input-dependent. Feed the pattern a well-formed address such as [email protected] and the engine's first attempt succeeds immediately, so unit tests built around valid examples never see a problem. Feed it a string of thirty-two a's followed by an exclamation mark — no @ anywhere — and the match fails, but not before the engine enumerates every way the ambiguous double quantifier could partition those characters. The author puts that search at roughly 2^N steps for N characters.
One thread, everyone queued
Because Node.js executes JavaScript on a single event-loop thread, the cost is not contained to the offending request. While the regex engine grinds through the combinatorial explosion, no other callbacks, I/O completions or incoming requests get processed, so every concurrent user of the API is effectively frozen out until the match attempt finishes.
Three smells to flag in review
The post distills vulnerable shapes into three families worth looking for during code review:
- Nested quantifiers, such as
(a+)+, a character class quantified twice, or(.*a){2,} - Overlapping alternation inside a repeated group, such as
(a|aa)+or(\w|\d)+, where multiple branches can consume the same text - Multiple unbounded wildcards within one expression, such as
.*.*followed by a literal
The fix is structural
Rather than tuning the expression incrementally, the recommended repair flattens the double-quantified group into a single linear character class — ^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$ in the email case — so the engine has only one way to consume each character. The post also advises enforcing a maximum input length before invoking .test(), since bounded input bounds the worst-case search.
Tooling to catch it in CI
Alongside the explanation, the author released redos-lint, a zero-dependency, MIT-licensed Node.js CLI that flags these heuristic patterns and is intended to run in CI, with its test suite passing under node --test. Browser-based regex visualizer and tester tools accompany it, and the post notes they keep test strings entirely in local memory, uploading nothing.
Why it matters
ReDoS sits in an uncomfortable blind spot: the vulnerable pattern passes every test built on inputs it was written to accept, because the exponential cost only shows up on input that fails to match. The attack surface is minimal — one modest request — while the blast radius is the entire process, since the event loop serves every connection. That makes it an availability risk rather than a mere code-quality nit, and the detection heuristics are cheap enough to automate in review and CI before a copy-pasted validator ever reaches production.
- #regex
- #node-js
- #javascript
- #security
- #denial-of-service