ReDoS — Regular Expression Denial of Service

DoS · All ecosystems
Definition

ReDoS (Regular Expression Denial of Service) exploits how some regular expressions behave with certain inputs — specifically, regex engines that use backtracking can take exponentially longer as input length increases when given a carefully crafted string. A single malicious HTTP request containing a few hundred characters can hang a Node.js server for seconds or cause a complete CPU lockup.

How backtracking causes ReDoS

Most regex engines use backtracking — when a pattern doesn't match, the engine tries alternative paths. For certain patterns, this creates an explosion of possibilities. Consider a regex like (a+)+ against the input aaaaaaaaX. The engine tries every possible way to group the a's before concluding no match — the number of attempts grows exponentially with input length.

ReDoS in popular packages

Why Node.js is especially vulnerable

Node.js runs JavaScript in a single-threaded event loop. A ReDoS attack that hangs the regex engine for 2 seconds doesn't just slow down one request — it blocks all other requests for those 2 seconds. A moderate-scale attack can completely take down a Node.js server with minimal bandwidth.

Detection

The ReDoS checker can identify vulnerable regex patterns in your own code. For dependencies, PackageFix flags packages with known ReDoS CVEs.

Paste your manifest — get a fixed version with all CVEs patched in seconds.

Open PackageFix →

Free · No signup · No CLI · Runs in your browser

Common questions

Is ReDoS a critical vulnerability?
ReDoS is typically rated HIGH (7.5) rather than CRITICAL because it causes denial of service rather than data theft or code execution. However, for single-threaded runtimes like Node.js, a well-crafted ReDoS can completely take down a service — which is functionally critical in production.
How do I test if my regex is vulnerable?
Use a ReDoS checker tool or run the regex against increasingly long crafted inputs and check if evaluation time grows exponentially. Safe regex patterns use possessive quantifiers or atomic groups when available in your language.
Does multi-threading protect against ReDoS?
Partially. In multi-threaded applications, only the affected thread is blocked, so other requests continue. But if enough ReDoS requests come in simultaneously, all threads can be occupied. Node.js is most vulnerable due to its single-threaded model.
How does PackageFix handle ReDoS CVEs?
PackageFix checks all package versions against OSV which includes ReDoS CVEs. They're flagged with HIGH severity. The fix is always a package update — the library must patch the vulnerable regex.

Related