No Login Data Private Local Save

Regex Injection / ReDoS Tester - Online Safe Pattern Test

8
0
0
0

ReDoS Vulnerability Tester

Detect Regular Expression Denial of Service (ReDoS) vulnerabilities & regex injection risks. Safely test patterns with timeout protection and static analysis.

Web Worker Sandbox 5s Timeout
/ /
Flags:
Presets:
Attack string generated based on pattern analysis
Testing in sandboxed worker...

No test results yet

Enter a regex pattern and click "Run ReDoS Test" to begin.

--
Ready

Run a test to assess vulnerability.

Execution Time --
0ms 10ms 100ms 1s 5s+
Waiting...
Detected Vulnerability Patterns

No patterns analyzed yet.

Fix Suggestions
Sandbox idle

Frequently Asked Questions

What is a ReDoS attack?
ReDoS (Regular Expression Denial of Service) is a type of attack that exploits the backtracking behavior of regex engines. By crafting a malicious input string, an attacker can cause a regex to take exponentially long to evaluate—potentially seconds, minutes, or even hours—consuming CPU resources and denying service to legitimate users. This is especially dangerous on server-side applications where a single slow regex can block the entire event loop or thread pool.
Which regex patterns are vulnerable to ReDoS?
The most common dangerous patterns include:

1. Nested quantifiers: (a+)+, (x*)*, (.+){2,}
2. Overlapping alternation: (a|aa|aaa)+b — where branches can match the same characters
3. Quantified optional groups: (x?)+, ([,-]?)+
4. Greedy quantifiers before optional parts: .*=.* on input with no =
5. Multiple overlapping .* patterns: .*.*.*

The common trait: exponential backtracking when the regex engine tries all possible ways to split the match.
How does this tester detect ReDoS vulnerabilities?
This tool uses a two-pronged approach:

1. Static Analysis: Scans the regex pattern for known dangerous structures (nested quantifiers, overlapping alternation, etc.) using pattern-matching rules.

2. Safe Execution Test: Runs the regex against an auto-generated attack string inside a sandboxed Web Worker with a 5-second timeout. If the worker is terminated due to timeout, it confirms a severe ReDoS vulnerability. If it completes, the execution time is measured and compared against safe thresholds.

The combination of static analysis and empirical testing provides a comprehensive vulnerability assessment.
What is regex injection and how is it related?
Regex injection occurs when user-supplied input is directly incorporated into a regular expression without proper sanitization. An attacker can inject:

• ReDoS patterns: e.g., injecting (a+)+ to cause denial of service
• Pattern-altering metacharacters: e.g., | to bypass filters, .* to match everything
• Unexpected flags or modifiers

Prevention: Always escape user input before using it in regex patterns (use regexEscape() utilities), validate and limit input length, and avoid constructing dynamic regex from untrusted sources whenever possible.
How can I fix a ReDoS-vulnerable regex?
1. Remove unnecessary nesting: Change (a+)+ to a+
2. Simplify alternation: Change (a|aa|aaa)+ to a+
3. Use possessive quantifiers (not supported in JS, but can be simulated with atomic groups in some engines): a++ instead of a+
4. Limit repetition: Use {1,10} instead of + or * when possible
5. Use non-backtracking constructs: Leverage lookahead assertions carefully
6. Pre-validate input length: Limit the length of strings passed to complex regex
7. Use a DFA-based regex library (like re2 for Node.js) that guarantees linear-time matching

This tool provides specific fix suggestions based on the detected patterns.
Are all regex engines equally vulnerable?
No. Regex engines fall into two categories:

Backtracking engines (vulnerable): JavaScript (V8, SpiderMonkey, JSC), Python (re module), PHP (pcre), Ruby, Perl, .NET (by default). These can exhibit exponential worst-case behavior.

DFA/Thompson NFA engines (resistant): Go (regexp), Rust (regex crate), RE2 (C++/Node.js binding), PostgreSQL ~ operator. These guarantee O(n) time complexity.

Since JavaScript is widely used for both frontend and backend (Node.js), ReDoS is a critical concern for web developers. Chrome's V8 has some optimizations but is not immune to ReDoS.

Security note: All regex testing is performed in an isolated Web Worker with a hard 5-second timeout. Your browser's main thread is never blocked. No data is sent to any server — everything runs locally in your browser. For production regex security, consider using RE2 or similar DFA-based engines, and always validate user input length.