Pydantic AI: Event loop blocked by quadratic title extraction in `web_fetch`GHSA-fpf4-vwcp-v4hp
MEDIUMFix: pydantic/pydantic-ai#8397GHSA-fpf4-vwcp-v4hp is a medium-severity (CVSS 6.5) CWE-1333 vulnerability in pydantic-ai. A fix is available for pydantic-ai — see the affected versions and patch details below.
Exploitation Status
No confirmed exploitation observed yet
- CISA’s own triage has not observed active exploitation or public proof-of-concept code for this CVE as of its last assessment.
Exploitation and automatability from CISA’s SSVC triage for GHSA-fpf4-vwcp-v4hp.
EPSS Exploitation Probability
Probability of exploitation in the next 30 days, from FIRST.org EPSS.
How urgent is this, really
GHSA-fpf4-vwcp-v4hp by exploitation likelihood (EPSS) against impact (CVSS). Outside the shaded patch-first corner.
Where this sits among everything scored
Of 394,803 CVEs with a current EPSS score, this one falls in the < 10% band (highlighted). Counts from FIRST.org, log-scaled.
Real-World Exposure
pydantic-ai🐍pydantic-ai🐍pydantic-ai-slim🐍pydantic-ai-slimReal-time download stats are indexed for npm and PyPI packages. This vulnerability affects PyPI packages — download data is not available via public APIs for these ecosystems.
Description
Summary
The local web-fetch tool (web_fetch_tool, also used as the WebFetch capability's local fallback) processed responses with several steps whose running time grows quadratically with the size of certain server-controlled inputs, and ran them on the event loop: decoding the body with whichever charset the server declared, extracting the page title with a backtracking regular expression, and converting the HTML to markdown. An application that exposes this tool to untrusted prompts can be steered to fetch an attacker-controlled page of a megabyte or two that blocks the event loop for minutes, stalling every other coroutine in the process — other agent runs, other requests being served — for the duration.
This is an availability issue only. SSRF protections and the download size limit introduced in GHSA-v2xh-2vp8-57h8 are unaffected; that limit bounds how much is downloaded, not how long the response takes to process.
Details
Title extraction used a backtracking pattern over the raw response body, so a body made of repeated unterminated tag openings cost time proportional to the square of its size. The HTML-to-markdown conversion had the same shape in three of its steps: normalizing whitespace, stripping preformatted blocks, and numbering ordered lists all took time proportional to the square of a run of spaces or a list's length. All of it ran on the event loop, and the regex steps hold the interpreter lock even when moved off it, so the whole process paid for the size of a server-controlled response.
The response body was also decoded on the event loop with the codec named by the charset parameter of the response's Content-Type, looked up in Python's codec registry. That registry includes punycode, whose decoder takes time proportional to the square of its input: a response of about one megabyte labelled charset=punycode blocked the event loop for roughly half a minute, with no HTML required. The registry also includes codecs that aren't text encodings at all, such as rot_13 and base64_codec; a response labelled with one of those raised an unexpected exception out of the tool, aborting the agent run that fetched it.
Separately, the HTML-to-markdown conversion recursed once per nested element, so a page nested a few hundred elements deep raised a RecursionError out of the tool, aborting the agent run that fetched it. A JSON response nested deeper than the interpreter allows did the same. These only affect that one run.
Who Is Affected
You are affected if your application registers the local web-fetch tool (or relies on the WebFetch capability's local fallback) and exposes the agent to untrusted prompts. allowed_domains narrows the exposure to pages on those domains but does not remove it. Applications that only fetch developer-controlled URLs are not exposed to the model-chosen attack path.
Remediation
Upgrade to a patched version. The title is now found with a single linear scan, the conversion steps above run in linear time, and decoding, title extraction and conversion all run in a worker thread. A charset naming a codec that isn't a text encoding, and a page too deeply nested to convert, are reported back to the model as a failed fetch instead of aborting the run; a JSON body too deeply nested to parse is returned as plain text.
Credits
Reported privately by @BrianWillows, whose report covered the quadratic title extraction. The response decoding, the codecs that are not text encodings, and the quadratic steps in the HTML-to-markdown conversion were found while fixing it.
Affected Packages
| Ecosystem | Package | Vulnerable range | Fix |
|---|---|---|---|
| 🐍PyPI | pydantic-ai | ≥ 1.77.0&&< 1.107.6 | 1.107.6pip install --upgrade 'pydantic-ai==1.107.6' |
| 🐍PyPI | pydantic-ai | ≥ 2.0.0b1&&< 2.44.0 | 2.44.0pip install --upgrade 'pydantic-ai==2.44.0' |
| 🐍PyPI | pydantic-ai-slim | ≥ 1.77.0&&< 1.107.6 | 1.107.6pip install --upgrade 'pydantic-ai-slim==1.107.6' |
| 🐍PyPI | pydantic-ai-slim | ≥ 2.0.0b1&&< 2.44.0 | 2.44.0pip install --upgrade 'pydantic-ai-slim==2.44.0' |
Affected Products
pydantic aipydanticDetection & mitigation playbook
Open-source dependencyDetect
Scan your dependency tree (package-lock.json, pnpm-lock.yaml, requirements.txt, go.sum, etc.) for pydantic-ai, including transitive dependencies — a direct dependency you never call can still pull in a vulnerable version.
Fix
Update pydantic-ai to 1.107.6 or later, then make sure no transitive (indirect) dependency still pins the vulnerable range — O3 confirms GHSA-fpf4-vwcp-v4hp is resolved across your whole dependency graph.
Workarounds
Restrict outbound requests from the affected component to an allowlist of hosts, block access to link-local and internal address ranges at the network layer, and require authentication on internal services so a forged request cannot reach them unauthenticated.
Fixing This On Your OS
If you run this on a Linux distribution, patch through your package manager against the distro's own security advisory below — it tracks the exact backported fix for your release, which can ship on a different timeline (and sometimes a different severity) than the upstream project.
A flaw of MODERATE impact was found in the pydantic-ai Python agent framework, which is shipped in Red Hat products including Red Hat Enterprise Linux AI (rhel-ai-3) and Lightspeed Core (lightspeed-core-0). The local web-fetch tool (web_fetch_tool, also used as the local fallback for the WebFetch capability) processes…
Mitigation for this issue is either not available or the currently available options do not meet the Red Hat Product Security criteria comprising ease of use and deployment, applicability to widespread installation base, or stability. Upstream's remediation is to upgrade to a patched version of pydantic-ai. Exposure can additionally be reduced by not exposing the web-fetch tool to untrusted prompts and restricting fetched URLs to developer-controlled locations; upstream notes that configuring allowed_domains narrows but does not remove the exposure.Source: Red Hat security advisory for GHSA-fpf4-vwcp-v4hp (CC BY 4.0)
Frequently Asked Questions
Is GHSA-fpf4-vwcp-v4hp in your dependencies?
Find it across PyPI, including transitive dependencies.