GitHub advisory · PyPI
Guard Core: Quadratic ReDoS in built-in detection pattern freezes the event loop with a single request
Description
A polynomial (quadratic) regular-expression denial of service in guard-core's built-in penetration-detection patterns allows any unauthenticated remote client to freeze every endpoint of an application for seconds per request, using only the default configuration. The triggering request completes without any detection match — no ban counter increments, no rate-limit violation is recorded — so it can be repeated indefinitely. Since guard-core 3.5.0, only custom patterns are executed through the compiler's timeout-protected create_safe_matcher(); all built-in patterns run as a bare, inline pattern.search(content) directly on the asyncio event loop. guard-core ≤ 3.4.0 ran built-ins through the safe matcher (verified in the 3.4.0 wheel, _check_regex_pattern), so this is a regression introduced in 3.5.0 — and it silently undoes the protection credited to GHSA-rrf6-pxg8-684g (CVE-2025-54365) and the unbounded-quantifier remediation of GHSA-j47q-rc62-w448 (CVE-2025-53539) for every stock pattern, despite the changelog advertising "Safe regex execution with configurable timeouts to prevent ReDoS attacks."
1. The pattern — guard_core/handlers/suspatterns_handler.py:519 (master 08780f1), the built-in template-injection detector:
r"\{\{\s*[^\}]+(?:system|exec|popen|eval|require|include)\s*\}\}"
On an input of { repeated N times, every one of the N−1 positions starts a \{\{ match attempt and [^\}]+ scans to end-of-string and backtracks once per position → O(N²). Note the sibling pattern at :524 (\{\%\s*[^\%]+...) is not vulnerable — its delimiter % is excluded from the character class, keeping scans bounded — which confirms the root cause is the unbounded, non-excluding [^\}]+.
2. The unprotected execution path — guard_core/handlers/suspatterns_handler.py:910-926:
if compiler:
if category == "custom":
safe_matcher = compiler.create_safe_matcher(pattern) #…
Manual fix · PyPI
pip install --upgrade "guard-core>=3.13.0"Sources