DevTools Logo

Regex Performance & ReDoS Tester

Regex Performance & ReDoS Tester

Benchmark patterns, sweep input lengths, and catch catastrophic backtracking before production.

Runs in your browser

Paste up to two patterns and a sample input, or build an adversarial input from a prefix, repeated character and failing suffix. The heuristic pass flags nested quantifiers, overlapping alternations and adjacent quantified tokens; the fixed-input bench reports median and p95 timings; the optional sweep runs each input length inside a worker with a 250 ms budget and fits a log-log growth curve. A kill or exponential slope is a DANGEROUS finding, while heuristics alone are advisory. All work happens locally.

Try an example

Patterns

no flags

Test input

Risk report

static analysis

No pattern yet

Type a pattern or load an example, then run the analysis.

Examples

Canonical ReDoS

Input
Pattern: (a+)+$
Input: aaaaaaaaaaaaaaaaaaaaaaaaaab
Output
High severity nested-quantifier finding; a sweep with the failing b suffix kills a run → DANGEROUS.

The suffix forces the engine to retry exponentially many partitions of the a run.

Safe refactor

Input
Pattern: ^a+$
Input: aaaaaaaaaaaaaaaa
Output
No static findings; linear sweep → SAFE.

One quantifier and an anchor leave the engine only one possible path.

Alternation with shared prefix

Input
Pattern: (abc|abd)
Output
Medium severity alternation finding; bench comparison against ab[cd] shows the cost of retrying.

A single character class removes the ambiguous shared prefix.

About this tool

Regex Performance & ReDoS Tester measures how a regular expression behaves as input grows, not just whether it matches. It combines a heuristic static pass with a repeated fixed-input bench and an optional length sweep whose curve fitting exposes super-linear backtracking.

The static pass flags three classic shapes: quantified groups whose body is itself quantified, alternation branches sharing a prefix, and adjacent overlapping quantifiers. The bench resets lastIndex on every run so median and p95 describe identical work; the sweep runs generated inputs at ten lengths inside a worker with a 250 ms budget and fits a log-log slope t ≈ n^k.

Verdicts combine both evidence streams. A killed run or exponential slope is DANGEROUS, a quadratic slope or a static red flag is SUSPECT, and near-linear growth with no findings is SAFE for the tested input class. Because engines differ, the verdict always describes this browser engine and these inputs — not a formal safety proof.

What this tool does not do

  • The static pass is a lightweight heuristic and can produce false positives or miss backreference-driven blowups.
  • The sweep cannot measure work beyond the 250 ms budget; a killed run is evidence of super-linear cost, not an exact timing.
  • Workers may be unavailable under restrictive CSP or in old WebViews; static analysis still runs and the tool explains the limitation.
  • Fixed-input benchmarks are capped at 100 kB and global match collection at 100 matches to keep the tab responsive.

How to use this tool

  1. Enter up to two patterns

    Type a pattern in A and optionally a refactored candidate in B. Add flags in the shared flags field; the compiled pattern is checked immediately.

  2. Choose test input

    Paste a realistic sample, or use the generator: a prefix, a repeated character, a failing suffix and a count. The failing suffix is what triggers catastrophic backtracking on patterns such as (a+)+$.

  3. Run the fixed-input bench

    Click Run analysis. Seven measured runs plus warmups report median and p95 timing for each pattern and a comparison factor.

  4. Run the length sweep

    Click Run sweep to time ten generated lengths in a worker. A run over the 250 ms budget terminates the worker and is itself the finding.

  5. Read the verdict and fix

    Review the static findings and remediation notes, then copy a markdown report for a ticket or pull request.

Use cases

Audit user-supplied patterns

Check a regex accepted from a config or form before it can hang a request handler.

Verify a refactor

Compare a vulnerable pattern with its rewritten version on the same adversarial input.

Security review evidence

Attach a sweep table and verdict to a ticket without shipping a profiler dump.

Evidence used for the verdict

SignalMeaning
Static finding: highNested or adjacent quantifiers with overlapping bodies; advisory until the sweep confirms it.
Static finding: mediumAlternation branches that share a prefix; often fixable by factoring or a character class.
Bench median / p95Repeated exec timings on one input with lastIndex reset between runs.
Sweep slope ≤ 1.5Near-linear growth for the tested length range and input class.
Sweep slope > 2.5 or killSuper-linear or runaway behaviour — DANGEROUS.

The static pass is a heuristic; the sweep is the authoritative behavioural evidence for the tested engine.

Common mistakes

Mistake:Sweeping a homogeneous a×n input against (a+)+$.

Fix:Add a failing suffix such as b; the pure repetition matches immediately and hides the vulnerability.

Mistake:Treating a SAFE verdict as a universal proof.

Fix:Re-test with adversarial inputs on the target engine; verdicts describe the tested engine and input class.

Mistake:Trusting static findings without a sweep.

Fix:Use heuristics to choose inputs, then let the timing curve decide.

Mistake:Benchmarking with the global flag and never resetting lastIndex.

Fix:The bench creates a fresh regex for each measured run, so each timing is the same work.

Frequently asked questions

What is catastrophic backtracking?

It happens when a regex engine can partition the same input in many ways and retries those partitions after a mismatch. A pattern like (a+)+$ against a long run of a followed by b can take exponential time, because the engine tries exponentially many ways to split the run before giving up.

How does the length sweep work?

The tool generates adversarial input at ten lengths from 10 to 10,000 characters using the prefix, repeated character and failing suffix you set. Each length is timed inside a worker with a 250 ms budget. Completed points are fitted with a log-log slope t ≈ n^k: near 1 is linear, near 2 quadratic, above 2.5 exponential, and a killed run is treated as runaway evidence.

Why does the input need a failing suffix?

A pure repetition such as aaaa… matches (a+)+ instantly, so it does not exercise the backtracking path. Adding a suffix that cannot match, such as b, forces the engine to abandon every candidate partition and reveals the vulnerability.

Are the static findings definitive?

No. They are heuristics that flag shapes known to be risky: nested or adjacent quantifiers with overlapping bodies, and alternations sharing a prefix. Engine optimisations can make some findings harmless, and exotic vulnerabilities can be missed. The sweep is the authoritative behavioural evidence for the engine and inputs you test.

Why can't the browser just stop a runaway regex?

JavaScript has no per-regex timeout. A catastrophic match blocks its thread until it finishes. The tool therefore runs timed exec calls in a dedicated worker and terminates that worker when the budget is exceeded; the page stays interactive and the kill becomes a result.

What fixes a vulnerable pattern?

Flatten nested quantifiers (use [a-z]+ instead of ([a-z]+)+), factor shared prefixes into a single path or character class, anchor the pattern and cap input length. If user-supplied patterns must be accepted, consider a linear-time engine such as RE2 instead of a backtracking engine.

Does the tool upload my patterns or input?

No. Compilation, static analysis, benchmarking and the worker sweep all run in your browser tab. Nothing is sent to a server and nothing is persisted by default.

References & standards