GHSA-R7HM-RJVG-XX7J

Vulnerability from github – Published: 2026-11-19 22:49 – Updated: 2026-11-19 22:49
VLAI
Summary
Guard Core: Quadratic ReDoS in built-in detection pattern freezes the event loop with a single request
Details

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.

Show details on source website

{
  "affected": [
    {
      "database_specific": {
        "last_known_affected_version_range": "\u003c= 3.12.0"
      },
      "package": {
        "ecosystem": "PyPI",
        "name": "guard-core"
      },
      "ranges": [
        {
          "events": [
            {
              "introduced": "3.5.0"
            },
            {
              "fixed": "3.13.0"
            }
          ],
          "type": "ECOSYSTEM"
        }
      ]
    }
  ],
  "aliases": [
    "CVE-2026-129302"
  ],
  "database_specific": {
    "cwe_ids": [
      "CWE-1333",
      "CWE-400"
    ],
    "github_reviewed": true,
    "github_reviewed_at": "2026-11-19T22:49:33Z",
    "nvd_published_at": "2026-11-16T20:19:01Z",
    "severity": "HIGH"
  },
  "details": "### Summary\n\nA polynomial (quadratic) regular-expression denial of service in guard-core\u0027s 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 \u2014 no ban counter increments, no rate-limit violation is recorded \u2014 so it can be repeated indefinitely. Since guard-core 3.5.0, only *custom* patterns are executed through the compiler\u0027s 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 \u2264 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** \u2014 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.\"\n\n### Details\n\n**1. The pattern** \u2014 `guard_core/handlers/suspatterns_handler.py:519` (master `08780f1`), the built-in template-injection detector:\n\n```python\nr\"\\{\\{\\s*[^\\}]+(?:system|exec|popen|eval|require|include)\\s*\\}\\}\"\n```\n\nOn an input of `{` repeated N times, every one of the N\u22121 positions starts a `\\{\\{` match attempt and `[^\\}]+` scans to end-of-string and backtracks once per position \u2192 O(N\u00b2). Note the sibling pattern at `:524` (`\\{\\%\\s*[^\\%]+...`) is **not** vulnerable \u2014 its delimiter `%` is excluded from the character class, keeping scans bounded \u2014 which confirms the root cause is the unbounded, non-excluding `[^\\}]+`.\n\n**2. The unprotected execution path** \u2014 `guard_core/handlers/suspatterns_handler.py:910-926`:\n\n```python\nif compiler:\n    if category == \"custom\":\n        safe_matcher = compiler.create_safe_matcher(pattern)   # executor + timeout\n        match = safe_matcher(content)\n        ...\n    else:\n        match = pattern.search(content)                        # \u2190 inline, NO timeout\n```\n\nIn enhanced mode (the default whenever a `SecurityConfig` is present \u2014 `_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 \u2264 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.\n\n**3. Default reachability** \u2014 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.\n\n**Measured** (CPython 3.14, guard-core 3.12.0):\n\n| input | detect() wall time | event-loop lag (measured in-process) |\n|---|---|---|\n| `{` \u00d7 2,500 | 0.15 s | \u2014 |\n| `{` \u00d7 5,000 | 0.46 s | \u2014 |\n| `{` \u00d7 10,000 | **1.85 s** | **2.57 s cumulative** across the three calls |\n\nClean 4\u00d7 per doubling \u2014 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*\\}\\}`).\n\n**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 `{`\u00d710,000 measured **44.03 s of continuous event-loop blockage from one request**, returning normally with no detection hit.\n\n**Why rate limiting doesn\u0027t 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 \u00d7 44 s = **440 s of loop blockage per 60 s window from a single IP** \u2014 single-source saturation, no distribution needed.\n\n**Framework reach:** any adapter embedding guard-core on an asyncio loop \u2014 fastapi-guard, flaskapi-guard (async deployments), djapi-guard (ASGI) \u2014 shares the loop with the application, so the freeze takes down every endpoint of the host application, not just the guarded routes.\n\n### PoC\n\n**guard-core only \u2014 no framework adapter needed.** Requires `pip install guard-core`, then `python poc_guard_core_redos.py`. Exit code 0 = freeze reproduced.\n\n```python\n\"\"\"PoC: event-loop ReDoS in guard-core (\u003e= 3.5.0, \u003c= 3.12.0), default config.\n\nThe built-in template-injection pattern is quadratic on \u0027{\u0027 x N, and since 3.5.0\nbuilt-in patterns execute inline (pattern.search) with NO timeout \u2014 only\n`custom` patterns get the compiler\u0027s safe matcher. One detect() call with a\n10,000-char value blocks the event loop ~1.8s; a 256KB JSON body with ~25 such\nfields blocks it ~44s. Runs on the asyncio loop that any adapter\n(fastapi-guard, flaskapi-guard, djapi-guard) shares with the app.\n\nRun:  python poc_guard_core_redos.py\nExit code 0 = freeze reproduced (max loop lag \u003e 1s).\n\"\"\"\n\nimport asyncio\nimport time\n\nfrom guard_core.handlers.suspatterns_handler import sus_patterns_handler\nfrom guard_core.models import SecurityConfig\n\nLOOP_LAGS: list[float] = []\n\n\nasync def _loop_lag_monitor() -\u003e None:\n    while True:\n        t0 = time.monotonic()\n        await asyncio.sleep(0.05)\n        LOOP_LAGS.append(time.monotonic() - t0 - 0.05)\n\n\nasync def main() -\u003e int:\n    config = SecurityConfig(enable_redis=False)  # defaults = enhanced mode\n    sus_patterns_handler.configure(config)\n\n    monitor = asyncio.create_task(_loop_lag_monitor())\n    await asyncio.sleep(0.3)  # baseline samples\n\n    for n in (2_500, 5_000, 10_000):\n        t0 = time.perf_counter()\n        result = await sus_patterns_handler.detect(\n            content=\"{\" * n, ip_address=\"203.0.113.7\", context=\"query_param:q\"\n        )\n        print(f\"\u0027{{\u0027 x {n:5d}: {time.perf_counter()-t0:.2f}s  is_threat={result[\u0027is_threat\u0027]}\")\n\n    # let the starved monitor task wake and record the lag it just endured\n    await asyncio.sleep(0.1)\n    max_lag = max(LOOP_LAGS)\n    print(f\"\\nmax event-loop lag during run: {max_lag:.2f}s\")\n    print(\"VERDICT:\", \"FROZEN\" if max_lag \u003e 1.0 else \"not reproduced\")\n\n    monitor.cancel()\n    return 0 if max_lag \u003e 1.0 else 1\n\n\nif __name__ == \"__main__\":\n    raise SystemExit(asyncio.run(main()))\n```\n\n**Observed output** (Python 3.14, guard-core 3.12.0):\n\n```\n\u0027{\u0027 x  2500: 0.16s  is_threat=False\n\u0027{\u0027 x  5000: 0.51s  is_threat=False\n\u0027{\u0027 x 10000: 1.91s  is_threat=False\n\nmax event-loop lag during run: 2.57s\nVERDICT: FROZEN\n```\n\nAn 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** \u2014 available on request.\n\n### Impact\n\n**Kind of vulnerability:** Regular Expression Denial of Service \u2014 CWE-1333 / CWE-400. Polynomial (quadratic) runtime, O(N\u00b2), not exponential backtracking.\n\n**Who is impacted:** every application embedding guard-core \u2265 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 \u2014 the attack is invisible in guard-core\u0027s own telemetry.\n\n**Fix directions:** (1) bound the quantifier in the template pattern (its `{%` sibling at `:524` is already safe because `[^\\%]+` excludes the delimiter \u2014 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 \u2264 3.4.0 behavior that the changelog advertises.\n\n\n\n## Reporter validation request\n\nThe 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\u0027s discussion thread or open a new issue with the result.",
  "id": "GHSA-r7hm-rjvg-xx7j",
  "modified": "2026-11-19T22:49:33Z",
  "published": "2026-11-19T22:49:33Z",
  "references": [
    {
      "type": "WEB",
      "url": "https://github.com/Guard-Core/guard-core/security/advisories/GHSA-r7hm-rjvg-xx7j"
    },
    {
      "type": "ADVISORY",
      "url": "https://nvd.nist.gov/vuln/detail/CVE-2026-129302"
    },
    {
      "type": "WEB",
      "url": "https://github.com/Guard-Core/guard-core/pull/68"
    },
    {
      "type": "WEB",
      "url": "https://github.com/Guard-Core/guard-core/commit/c07239fa1c5aa93e3f179440e79dad652977d3e4"
    },
    {
      "type": "WEB",
      "url": "https://github.com/Guard-Core/guard-core/releases/tag/3.13.0"
    },
    {
      "type": "PACKAGE",
      "url": "https://github.com/rennf93/guard-core"
    }
  ],
  "schema_version": "1.4.0",
  "severity": [
    {
      "score": "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H",
      "type": "CVSS_V3"
    }
  ],
  "summary": "Guard Core: Quadratic ReDoS in built-in detection pattern freezes the event loop with a single request"
}



Log in or create an account to share your comment.




Tags
Taxonomy of the tags.


Loading…

Loading…

Loading…

Forecast uses a logistic model when the trend is rising, or an exponential decay model when the trend is falling. Fitted via linearized least squares.

Sightings

Author Source Type Date Other

Nomenclature

  • Seen: The vulnerability was mentioned, discussed, or observed by the user.
  • Confirmed: The vulnerability has been validated from an analyst's perspective.
  • Published Proof of Concept: A public proof of concept is available for this vulnerability.
  • Exploited: The vulnerability was observed as exploited by the user who reported the sighting.
  • Patched: The vulnerability was observed as successfully patched by the user who reported the sighting.
  • Not exploited: The vulnerability was not observed as exploited by the user who reported the sighting.
  • Not confirmed: The user expressed doubt about the validity of the vulnerability.
  • Not patched: The vulnerability was not observed as successfully patched by the user who reported the sighting.

Loading…

Loading…

Loading…

Related by attack behaviour

Vulnerabilities whose description is nearest to this one in the vector space of the CIRCL/vulnerability-attack-technique-biencoder model. This is a similarity search over the bi-encoder space (plain cosine), not a classification, and it has no measured accuracy.


Loading…