security: mitigate ReDoS in proxy view_request regex search#876
security: mitigate ReDoS in proxy view_request regex search#876Sunil56224972 wants to merge 1 commit into
Conversation
The _format_search_hits() helper compiles a user-supplied regex pattern and runs it against HTTP response bodies via finditer(). A crafted pattern with catastrophic backtracking (e.g. '(a+)+$') can hang the agent's event loop indefinitely since this runs under the shared _CAIDO_CALL_LOCK. Mitigations applied: 1. Truncate the search content to 1 MiB before running the regex. This bounds the worst-case CPU time even for pathological patterns, since backtracking complexity is at least proportional to input size. 2. Catch RecursionError during finditer() -- some patterns hit Python's recursion limit on large inputs. 3. Warn the caller when content was truncated so results are understood as partial.
Greptile SummaryThis PR attempts to mitigate regex denial of service in proxy request searching.
Confidence Score: 3/5This PR is not safe to merge until regex execution receives an enforceable runtime bound or is moved to an execution context that can be terminated. The synchronous Python regex search can perform catastrophic backtracking on adversarial content far below the new 1 MiB cap, blocking the event loop before asynchronous timeout handling can run. Files Needing Attention: strix/tools/proxy/tools.py
|
| Filename | Overview |
|---|---|
| strix/tools/proxy/tools.py | Adds truncation and exception handling around proxy regex searches, but leaves the targeted CPU-exhaustion path reachable because synchronous backtracking has no runtime bound. |
Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 1
strix/tools/proxy/tools.py:320-323
**Regex execution remains unbounded**
When an agent searches an adversarial HTTP body with a catastrophic-backtracking expression such as `(a+)+$`, truncating the body to 1 MiB still permits exponential work on much shorter inputs, causing the synchronous search to block the event loop indefinitely; catching exceptions after `finditer()` returns does not enforce an execution bound.
**How this was verified:** `view_request` passes the agent-supplied pattern and decoded HTTP content directly to synchronous `regex.finditer()` without a regex timeout or interruptible execution boundary.
Reviews (1): Last reviewed commit: "security: mitigate ReDoS in proxy view_r..." | Re-trigger Greptile
| _MAX_SEARCH_LEN = 1_048_576 # 1 MiB | ||
| search_content = content[:_MAX_SEARCH_LEN] | ||
| truncated = len(content) > _MAX_SEARCH_LEN | ||
|
|
There was a problem hiding this comment.
Regex execution remains unbounded
When an agent searches an adversarial HTTP body with a catastrophic-backtracking expression such as (a+)+$, truncating the body to 1 MiB still permits exponential work on much shorter inputs, causing the synchronous search to block the event loop indefinitely; catching exceptions after finditer() returns does not enforce an execution bound.
How this was verified: view_request passes the agent-supplied pattern and decoded HTTP content directly to synchronous regex.finditer() without a regex timeout or interruptible execution boundary.
Knowledge Base Used: Tools Overview
Prompt To Fix With AI
This is a comment left during a code review.
Path: strix/tools/proxy/tools.py
Line: 320-323
Comment:
**Regex execution remains unbounded**
When an agent searches an adversarial HTTP body with a catastrophic-backtracking expression such as `(a+)+$`, truncating the body to 1 MiB still permits exponential work on much shorter inputs, causing the synchronous search to block the event loop indefinitely; catching exceptions after `finditer()` returns does not enforce an execution bound.
**How this was verified:** `view_request` passes the agent-supplied pattern and decoded HTTP content directly to synchronous `regex.finditer()` without a regex timeout or interruptible execution boundary.
**Knowledge Base Used:** [Tools Overview](https://app.greptile.com/strix-org-3/-/custom-context/knowledge-base/usestrix/strix/-/docs/tools-overview.md)
How can I resolve this? If you propose a fix, please make it concise.
Summary
The
_format_search_hits()helper instrix/tools/proxy/tools.pycompiles a user-supplied regex pattern and runs it against HTTP response bodies viafinditer(). A crafted pattern with catastrophic backtracking (e.g.(a+)+$) can hang the agent's event loop indefinitely since this runs under the shared_CAIDO_CALL_LOCK.Severity: Medium
While the regex pattern comes from the AI agent (not directly from an external attacker), a malicious target application could return content specifically designed to trigger catastrophic backtracking against common patterns the agent might use.
Mitigations applied
RecursionErrorduringfinditer()— some patterns hit Python's recursion limit on large inputsFiles changed
strix/tools/proxy/tools.pyTesting