The vulnerability CVE-2026-107294 describes an unbounded memory use issue in Pydantic AI when downloading remote content via web_fetch or FileUrl. The core problem was that download helpers buffered entire HTTP response bodies into memory before enforcing any size limits. This could lead to denial of service by exhausting process memory.
My analysis focused on the provided commit 7a64d049c3f5271a975cd1d64b2fa876d83ede1d (and its counterpart e3824a58c82864ed26afb2887619834a4eb86cc8, which shows identical fixes for a different version branch). The changes clearly indicate the introduction of size limits during content download.
-
safe_download in pydantic_ai_slim/pydantic_ai/_ssrf.py: This function is the central download utility. The patch introduces a max_bytes parameter and modifies the HTTP request logic. Previously, client.get() was used, which buffers the entire response. The fix introduces streaming (client.send(request, stream=True)) and new helper functions (_read_capped_body, _read_capped_identity, _read_capped_gzip) to enforce the max_bytes limit while reading the stream. The original safe_download function, when called without a size limit, was the direct cause of the unbounded memory usage.
-
WebFetchLocalTool.__call__ in pydantic_ai_slim/pydantic_ai/common_tools/web_fetch.py: This method is part of the web_fetch_tool functionality. Before the patch, it called safe_download without passing any size constraints. The patch adds max_bytes=self.max_download_bytes to this call, indicating that this function was a direct caller of the vulnerable safe_download without mitigation.
-
download_item in pydantic_ai_slim/pydantic_ai/models/__init__.py: This function handles downloads for FileUrl types (like ImageUrl, DocumentUrl). Similar to WebFetchLocalTool.__call__, it previously called safe_download without any max_bytes argument. The patch modifies this call to include max_bytes=_MAX_FILE_URL_DOWNLOAD_BYTES, confirming its role in triggering the unbounded download behavior.
These three functions represent the critical path where untrusted input (a URL pointing to a large file) could lead to excessive memory consumption. safe_download is the underlying mechanism, while WebFetchLocalTool.__call__ and download_item are the entry points that utilized this mechanism without proper safeguards.