In async Python, a synchronous regex running before your size limit is an unauthenticated CPU denial-of-service vector.
Your guardrail regex didn't protect your agent. It froze your entire Python event loop.
What changed
Pydantic AI v2.70.0 (released 17 November 2026) shipped with two high-severity security advisories in pydantic-ai-harness (GHSA-5m5q-5qj4-gx9h and GHSA-m4cr-m4qc-9hh3) that expose a dangerous architectural blind spot in how most engineering teams wire async agent guardrails and tool output sanitizers.
From the advisories, verbatim:
- Default JWT secret redaction (
GHSA-5m5q-5qj4-gx9h): > "The jwt pattern in Pydantic AI Harness's secret redaction backtracks in time quadratic in the length of the text it scanned, so a few hundred kilobytes of crafted text could occupy the event loop for tens of seconds to minutes." > "This affects applications that use the guardrail detectors redact_secrets or secret_data() with the jwt pattern, which is included by default, on text an attacker can influence: user prompts checked by InputGuardrail, tool results checked by ToolGuardrail, or model output checked by OutputGuardrail. Synchronous guards run on the event loop." - ANSI stripping before output truncation (
GHSA-m4cr-m4qc-9hh3): > "With strip_ansi=True, Pydantic AI Harness's ToolOutputLimits capability removed ANSI escape sequences with a pattern that took time quadratic in the length of a line, so a tool result of a few hundred kilobytes with many unterminated escape sequences could occupy the event loop for tens of seconds to minutes." > "Stripping runs on the event loop before the capability reduces the output, so its own size limits do not bound it."
Both vulnerabilities share the same root weakness: CWE-1333 (Inefficient Regular Expression Complexity) executing synchronously on the Python asyncio event loop before or independent of payload size limits.
The mechanics of an event-loop freeze
Almost every production Python agent service uses asyncio (via FastAPI, Starlette, or an async worker pool) so a single worker process can multiplex dozens of concurrent agent runs waiting on network I/O (LLM streams, vector searches, MCP calls).
To keep secrets out of logs and terminal garbage out of context windows, teams add guardrails and output limiters:
# Illustrative configuration of tool limits and secret redaction prior to 0.70.0 # You assume ToolOutputLimits caps output size, and redact_secrets just scrubs tokens. harness_capabilities = [ ToolOutputLimits(max_bytes=10_000, strip_ansi=True), ToolGuardrail(detector=redact_secrets()), # includes 'jwt' pattern by default ] Now trace what happens when an agent runs a tool whose output an external source can influence — fetching a web page, reading a repository file, running a shell command, or querying a third-party MCP server:
- The untrusted payload arrives: A tool returns a 300 KB single-line payload containing repeated
-eyJsegments or thousands of unterminated\x1b[ANSI escape prefixes (illustrative payload):
[ILLUSTRATIVE CRAFTED TOOL OUTPUT: 300 KB line] ... -eyJhbGciOi-eyJhbGciOi-eyJhbGciOi ... (or repeated \x1b[31;1;4m without terminator) - Sanitization runs before truncation: You configured
ToolOutputLimitsspecifically so oversized tool responses get cut down before eating your context window. Backwards ordering defeats it:strip_ansi=Trueran on the raw, unbounded string before the capability reduced the output. - Default regexes scan the full string on the main thread: Even if
strip_ansiwas left at its defaultFalse,redact_secretsandsecret_data()include thejwtregex pattern by default acrossInputGuardrail,ToolGuardrail, andOutputGuardrail. - Quadratic backtracking locks the CPU: Python's standard
reengine is a backtracking NFA. On crafted non-matching strings of length $N$, quadratic complexity $O(N^2)$ turns a 300 KB string scan into billions of backtracking steps. - The entire worker dies for 30–90 seconds: Because synchronous guardrails run directly on the
asyncioevent loop, the loop cannot yield at anawaitpoint while insidere.sub()orre.search().
Why this looks like a mysterious infrastructure outage
When an asyncio event loop blocks in C-level regex evaluation for 60 seconds:
- Every concurrent user on that worker freezes: Other agent runs waiting for a socket read or streaming token chunk stop mid-sentence.
- Health checks time out: Kubernetes
/healthzprobes cannot be answered by the blocked event loop, triggering pod restarts and cascading 502s. - WebSockets drop: Heartbeat pings expire while the thread is stuck inside the guardrail.
- The wrong component gets blamed: Engineers check LLM provider status pages and database connection pools, never suspecting that a "lightweight regex guardrail" burned 100% of one CPU core for a minute.
How pydantic-ai-harness 0.70.0 fixed it
In pydantic-ai-harness 0.70.0 (shipped with Pydantic AI v2.70.0):
- The ANSI stripping pattern in
ToolOutputLimitswas fixed to avoid quadratic backtracking on unterminated escape sequences. - The
jwtsecret redaction pattern was tightened so it no longer backtracks quadratically (specifically, as the release notes state: "The fixed pattern no longer matches a JWT whose header segment contains-eyJ."). - If you cannot upgrade immediately, the advisories document two immediate mitigations:
- Leave
strip_ansiat its default (False). - Exclude the
jwtpattern by explicitly whitelisting only the patterns you need:secret_data(only=[...]).
- Leave
The discipline for async agent guardrails
- Enforce hard byte-length ceilings before any regex or parser runs. A size limit that runs after a regex, HTML parser, or JSON sanitizer is not a size limit. Slice or reject by raw byte/character count at the I/O boundary first:
# Illustrative defensive ordering: bound size BEFORE running any regex MAX_SCAN_CHARS = 32_768 bounded_output = raw_tool_output[:MAX_SCAN_CHARS] sanitized_output = linear_time_scrubber(bounded_output) - Treat tool outputs as untrusted attacker-controlled input. Prompt injection isn't the only threat from a fetched webpage, file read, or MCP response. Resource exhaustion (ReDoS, decompression bombs, deeply nested JSON) enters through the exact same tool-result channel.
- Ban backtracking regexes on the
asyncioevent loop. Audit every custom regex in yourInputGuardrail,ToolGuardrail, andOutputGuardrailpipeline for CWE-1333 (nested quantifiers, overlapping alternations, unanchored greedy lookaheads), or replace Python's backtrackingremodule on untrusted inputs with a linear-time automaton engine (such asgoogle-re2or a Rust-backed scanner).
Two hard rules
A guardrail that runs before your size limit is an unauthenticated CPU denial-of-service vector.
In async Python, one quadratic regex on untrusted tool output freezes every user on the worker.
Honest limitation: I am reading Pydantic AI's v2.70.0 release notes and GitHub Security Advisories GHSA-5m5q-5qj4-gx9h and GHSA-m4cr-m4qc-9hh3. The configuration snippets and crafted payload examples above are illustrative; I have not run ReDoS payloads against a live deployment.
Checkable references:
- Pydantic AI v2.70.0 release notes (2026-11-17)
- GHSA-5m5q-5qj4-gx9h: Harness JWT redaction can take quadratic time, blocking the event loop
- GHSA-m4cr-m4qc-9hh3: Harness ToolOutputLimits ANSI stripping can take quadratic time, blocking the event loop
- MITRE CWE-1333: Inefficient Regular Expression Complexity
What this series is: one primary source a day — a spec, a changelog, a status page — and what actually changed, with the quote. Follow if you prefer the change over someone's summary.
In your agent stack today, do your regex scrubbers run before or after you enforce hard byte-length caps on tool outputs?

