Course contentsShow
← Security
Lesson 1182 of 3,05224. Application Security - Input ValidationFree lesson

Testing for ReDoS Vulnerabilities

Crafting test inputs to trigger worst-case regex behavior and measuring execution time to identify vulnerabilities.

Testing for ReDoS Vulnerabilities

What you'll learn: How to craft test inputs that expose catastrophic backtracking in regex patterns and measure execution time to confirm ReDoS vulnerabilities.

Why Testing Matters

You've learned what ReDoS is and how to spot dangerous patterns. Now you need to prove a vulnerability exists by triggering the worst-case behavior in a controlled way. Just looking at regex isn't enough—you must measure actual performance degradation.

The Core Testing Approach

Crafting Malicious Inputs: Start by identifying potentially evil regex patterns (nested quantifiers, overlapping alternations). Then build test strings designed to maximize backtracking:

  • For a pattern like (a+)+b, try input like aaaaaaaaaaaaaaaaaaaa! (many 'a's but no 'b')
  • Each extra character doubles the processing time exponentially
  • The pattern keeps trying different groupings of 'a's hoping to find a 'b'

Measuring Execution Time: Record how long the regex match takes with increasing input sizes:

  1. Test with 10 characters → 5ms
  2. Test with 15 characters → 50ms
  3. Test with 20 characters → 500ms
  4. Test with 25 characters → 5000ms (5 seconds!)

If time grows exponentially with linear input growth, you've confirmed ReDoS vulnerability.

Practical Testing Strategy

Gradual escalation: Start small to avoid accidentally DoS'ing your own test environment. Increase input length carefully, stopping when you see exponential behavior.

Automation: Use specialized tools (like regex analyzers you learned about) to generate worst-case inputs automatically rather than guessing.

Safe testing environment: Never test ReDoS on production—even testing can cause service disruption.

Key Takeaway:
Testing for ReDoS requires crafting inputs that maximize backtracking, then measuring execution time growth—exponential slowdown with linear input increases confirms the vulnerability.