The Regex Assassin
Difficulty: MEDIUMID: redos-cpu-killer
The Scenario
You are building a data validation pipeline that processes user-submitted strings before parsing them. To prevent malicious input, you run a local Python validator to check patterns before further processing.
The Incident
A user pasted a malformed pattern string into your API. Suddenly, your backend froze. No errors, no crash logs—just 100% CPU usage. Your downstream services are sitting idle, but your validation container is completely unresponsive.
The Stakes
- The Victim: Your validation service.
- The Culprit: A regex validator intended to check for repeating character patterns.
- The Result: A "ReDoS" (Regular Expression Denial of Service) that forces your CPU to check millions of paths for a single string.
The Goal
Patch the validate_pattern function.
- The current logic uses
^((A+)+)+$which has O(2^n) complexity. - Your Task: Rewrite the regex to accept valid patterns instantly (under 10ms) without hanging on malformed inputs.
solution.py
Loading...
⚠️ Do not include PII or secrets in your code.
SYSTEM_LOGS
5/5
// Waiting for execution trigger...