# GHSA-9845-MQQR-7RXP: SemanticAnalyzer request scan is quadratic in content length, letting plain repeated characters hold the event loop for seconds per request

- Database: GitHub
- Severity: CVSS 7.5 (High)
- Published: 2026-08-26
- Modified: 2026-08-26

## Affected versions

- guard-core (PyPI): from 1.0.0, fixed in 3.13.0

## Description

### Summary

`SemanticAnalyzer.analyze()` (`guard_core/detection_engine/semantic.py`), invoked by the default enhanced detection mode on every scanned request value, ran in time quadratic in the length of the scanned content. The blow-up is triggered by ordinary repeated characters with no attack syntax, so any unauthenticated request whose body reaches the analyzer consumes a large, fixed amount of CPU. The work runs on the event loop and cannot be cancelled by a timeout (a CPU-bound regex holds the GIL), so a small number of concurrent requests saturates a worker.

### Details

Four `attack_structures` patterns used unbounded greedy quantifiers whose character class did not exclude their own start character: `function_call` (`\w+\s*\([^)]*\)`), `path_traversal` (`\.{2,}[/\\]`), `url_pattern` (`[a-z]+://`) and `tag_like` (`<[^>]+>`). On non-matching input the outer scan tries O(n) start positions and each greedily consumes O(n) characters before failing, giving O(n^2) total. `detection_max_content_length` bounds the input length but not the quadratic factor.

Reachability was confirmed on the 3.12.0 tag: `guard_core/handlers/suspatterns_handler.py` calls `semantic_analyzer.analyze(content)` on scanned content with no length cap in the analyzer itself. No non-default option is required.

### Impact

- Trigger: a request body of repeated characters, for example the byte `a` repeated. No SQL, HTML or other attack syntax is required.
- Cost: `SemanticAnalyzer.analyze("a" * n)` grew about 4x per doubling of `n`: about 0.25 s at 2500 bytes, 0.99 s at 5000, 3.95 s at 10000, 15.8 s at 20000 (measured on the 1.0.0 through 3.12.0 code). At the default `detection_max_content_length` of 10000 the per-request cost is about 4 s of uncancellable CPU.
- Unauthenticated, remote, enabled by default wherever enhanced-mode detection scans request values. A handful of concurrent requests denies service to a worker.

### Fix

3.13.0 bounds `function_call` (`\w{1,64}\s*\([^)]{0,256}\)`), `path_traversal` (`\.{2,20}[/\\]`) and `url_pattern` (`[a-z]{1,32}://`) so per-position work is constant, and scans `tag_like` only up to the last `>` in the content (`_tag_scan_window`), making `analyze()` linear in input length. Measured after the fix: about 0.09 s at 20000 bytes versus 15.8 s before. Detection results on the 3.13.0 detection corpus are unchanged.

### Workarounds

For users who cannot upgrade: lower `detection_max_content_length` (the cost is quadratic in the capped length, so a smaller cap helps super-linearly, at the price of coverage on long bodies), and place a request-body size limit and a per-client rate limit in front of the application.

### Credit

Found during the guard-core 3.13.0 hardening review.

### Status

Filed retroactively on 2026-08-26. Fixed in [guard-core 3.13.0](https://github.com/rennf93/guard-core/releases/tag/3.13.0) (`SemanticAnalyzer` quantifiers bounded, `tag_like` scanned through `_tag_scan_window`); 3.14.0 keeps the fix and adds the per-request scan cap (GHSA-3hfx-8m47-5f9h).

## References

- https://github.com/Guard-Core/guard-core/security/advisories/GHSA-9845-mqqr-7rxp

Page: https://cve.now/GHSA-9845-MQQR-7RXP

Wrong or missing data? Send feedback: POST https://cve.now/api/v1/feedback (see https://cve.now/agents#feedback).
