GHSA-r7hm-rjvg-xx7j: Guard Core: Quadratic ReDoS in built-in detection pattern freezes the event loop with a single request
- Source:
- OSV.dev
- Published:
- Fetched:
- Updated:
- Affects:
- guard-core
https://osv.dev/vulnerability/GHSA-r7hm-rjvg-xx7j ↗
Guard Core: Quadratic ReDoS in built-in detection pattern freezes the event loop with a single request ### Summary 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." ### Details **1. The pattern** — `guard_core/handlers/suspatterns_handler.py:519` (master `08780f1`), the built-in template-injection detector: ```python 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`: ```python if compiler: if category == "custom": safe_matcher = compiler.create_safe_matcher(pattern) # executor + timeout match = safe_matcher(content) ... else: match = pattern.search(content) # ← inline, NO timeout ``` In enhanced mode (the default whenever a `SecurityConfig` is present — `_supports_enhanced_config()` is a duck-type attribute check a stock config always passes), all built-in patterns execute inline **inside the async coroutine**, blocking the event loop for the full scan. In guard-core ≤ 3.4.0, `_check_regex_pattern()` routed *every* pattern through `self._compiler.create_safe_matcher(pattern.pattern)` (verified in the 3.4.0 wheel, `suspatterns_handler.py:565-567`) or, without a compiler, through `_check_pattern_with_timeout` (4-worker pool + per-pattern timeout). The `category == "custom"` exemption appeared in 3.5.0. **3. Default reachability** — penetration detection is on by default (`enable_penetration_detection=True`), query parameters are scanned by default (`guard_core/utils.py:843-865`), and the default scan windo Affected: PyPI:guard-core Fixed in: 3.13.0 References: https://github.com/Guard-Core/guard-core/security/advisories/GHSA-r7hm-rjvg-xx7j https://nvd.nist.gov/vuln/detail/CVE-2026-129302 https://github.com/Guard-Core/guard-core/pull/68 https://github.com/Guard-Core/guard-core/commit/c07239fa1c5aa93e3f179440e79dad652977d3e4 https://github.com/Guard-Core/guard-core/releases/tag/3.13.0 https://github.com/rennf93/guard-core