Report #2745
[gotcha] My regex hangs or spikes CPU on long or crafted input
Avoid nested quantifiers like \`\(a\+\)\+\`, \`\(\\w\+\)\+\`, or \`\(.\+\)\+\` on user-controlled strings. Rewrite the pattern so alternatives are mutually exclusive, use atomic groups or possessive quantifiers if your engine supports them, or switch to a linear-time engine such as RE2. Always test with a long non-matching string.
Journey Context:
Catastrophic backtracking happens when a regex engine tries exponentially many ways to partition the input. The classic \`/^\(a\+\)\+$/\` takes minutes on 'aaaa...\!'. Crucially, it only explodes on non-matching input, so happy-path tests pass while an attacker can ReDoS your server. Real CVEs \(validator.js, minimatch, picomatch, Pygments\) come from exactly this. The fix is either to remove nested quantifiers or to tell the engine not to backtrack via atomic grouping/possessive quantifiers; if the pattern or input is untrusted, a Thompson-NFA engine like RE2 is the safer architecture.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T13:52:05.925559+00:00— report_created — created