TL;DR: Nested quantifiers and overlapping alternation in Python regexes can trigger catastrophic backtracking and denial of service, according to Semgrep. Availability reviews need to catch these patterns before untrusted input turns them into CPU-heavy failures.
Editorial analysis by NHI Mgmt Group, based on content published by Semgrep: “Bento check: Catch catastrophic backtracking ReDoS bugs”.
Key questions
Q: Why do inefficient regexes create denial-of-service risk?
A: Because regex evaluation cost can grow sharply when the engine must reconsider the same branches over and over.
Q: How do security teams know a regex is actually risky?
A: Look for structural warning signs such as nested repetition, overlapping alternation, or a trailing token that forces repeated backtracking.
Q: What breaks when a Python regex has nested quantifiers or overlapping alternation?
A: It can enter catastrophic backtracking, where the engine explores many match paths before failing, consuming CPU and slowing or stopping the application.
Practitioner guidance
- Audit regexes on critical code paths Search validation, parsing, and request-handling code for nested quantifiers and overlapping alternation patterns that can trigger catastrophic backtracking.
- Add regex checks to CI Run static analysis or equivalent heuristics in the build pipeline so risky expressions are blocked before release.
- Test patterns with adversarial inputs Use long repeated strings and non-matching suffixes to see whether a regex becomes CPU-bound under crafted input.
Bottom line: Inefficient Python regexes can create a denial-of-service condition when crafted input drives catastrophic backtracking.
Glossary terms: Catastrophic Backtracking, ReDoS, Nested Quantifiers, Overlapping Alternation
Explore further
View Full Forum → | NHI Foundation Course → | Our Services → | Read the full analysis →
Regex performance is now an application security control, not a code style issue. The article shows that backtracking risk can turn ordinary input validation into a denial-of-service condition. That shifts regex governance out of the “clean code” bucket and into secure development and runtime resilience. Practitioners should treat high-risk regexes as availability-sensitive logic and review them with the same discipline used for authentication paths.
A question worth separating out:
Q: What should teams do when regexes sit on authentication or request paths?
A: Treat them as availability-critical controls. Put them in secure development checks, cap their complexity where possible, and review any pattern that can block login, validation, or edge filtering if it begins to backtrack excessively.
👉 Read our full editorial: ReDoS risk in Python regexes exposes availability gaps