A vulnerability in Pydantic AI, the agent framework from the Pydantic team, allows third parties who control data returned by agent tools to trigger unintended file downloads or cloud storage access when message history is serialized and reloaded.
Quick Take
- What: CVE-2026-133505 in Pydantic AI rebuilds tool result data shaped like file objects as actual file downloads or provider file references after history reload
- Who is affected: Applications using pydantic-ai or pydantic-ai-slim versions 1.50.0 through 1.107.9 or 2.0.0b1 through 2.65.0 that store and reload message history containing tool results with third-party data
- Severity: Medium (CVSS 5.9)
- What to do: Upgrade to pydantic-ai 1.107.10 or 2.66.0, or run sanitize_messages() on stored history before reuse
In plain English
Pydantic AI is a framework for building AI agents. When an agent’s conversation history is saved and loaded later, the system tries to preserve files that tools returned. A bug caused it to also treat ordinary data that happened to look like a file as if it were a real file. An attacker who controls data that an agent tool returns could craft that data to look like a file, causing the application to download a file from the local network or make the AI provider read cloud storage using the application’s credentials.
What you should do: If you use Pydantic AI to build agents, upgrade to the patched version. If you don’t use Pydantic AI, you can ignore this.
What happened
When Pydantic AI serializes message history and loads it again, it rebuilds file items (ImageUrl, DocumentUrl, AudioUrl, VideoUrl, and UploadedFile) nested in tool results so that files a tool returned survive the round trip. The vulnerability occurred because a mapping that a tool returned as data, if it serialized to the same JSON shape as one of these file types, was rebuilt as a file when history was loaded.
During the original run, the model received that mapping as JSON text. After the reload, it became a file that the next model request would download or reference.
Tool results are serialized and loaded again when:
- The application stores message history and loads it later, for example with ModelMessagesTypeAdapter, including history a UI adapter loads with manage_message_history=’server’
- The agent runs with Temporal, DBOS, or Prefect durable execution, which serialize a tool’s result between steps within a single run
The assumed attacker is a third party with no access to the application who controls content that reaches a tool result, such as a record that an MCP server or a function tool returns from an external system. The MCP server and the tools themselves are trusted. No injected instructions are needed for the download or file reference to happen, only a later model request.
The impact depends on the file type the data is rebuilt as:
- A DocumentUrl or ImageUrl with force_download=’allow-local’ is downloaded by Pydantic AI with the private-network block turned off (cloud metadata addresses stay blocked). For a plain-text document, and for any model that honors force_download, the response body is sent to the model provider as part of the conversation. The attacker can obtain it if the model can be induced to repeat it, for example to a tool the attacker controls.
- A file URL with a non-HTTP scheme such as s3:// or gs://, or an UploadedFile, is resolved by the model provider with the application’s credentials. The attacker can name any object those credentials can read.
Applications are affected if all of the following apply:
- Tool results can contain data that third parties control, for example from an MCP server or from an external API whose JSON a tool returns unchanged
- Message history containing those results is serialized and loaded again (stored history, server-held UI adapter history, or durable execution)
- The model is one Pydantic AI downloads files for, or that honors force_download, or its provider resolves non-HTTP file URLs or uploaded files
History that a client submits through the Vercel AI or AG-UI adapter in the default mode is not affected. The adapters run sanitize_messages() on it, which resets force_download and drops non-HTTP URLs and uploaded files, including those nested in tool results.
What you should do
Upgrade to pydantic-ai or pydantic-ai-slim version 1.107.10 (if using 1.x) or 2.66.0 (if using 2.x).
Until you can upgrade:
- Run sanitize_messages() on stored history before reusing it. It resets force_download on file URLs in tool results and drops uploaded-file references and non-HTTP URLs. It also applies its other rules for untrusted history, such as removing unresolved tool calls at the end, so check those against how your application resumes runs.
- Have function tools return third-party data as a JSON string, for example with pydantic_core.to_json(data).decode(), rather than as a dict or list. A string is never rebuilt as a file.
To check history you have already stored, look for tool-return content containing “kind” values such as “document-url”, “image-url”, or “uploaded-file” that your own tools did not produce, especially with “force_download” set or a non-HTTP “url”.
What it means
The fix changes how Pydantic AI handles tool results during serialization. A tool result now records the file items it holds when it is serialized, outside the tool’s data, and loading rebuilds only those. A mapping that a tool returned stays a mapping, whatever its shape.
History saved by an earlier version has no such record. In it, a mapping shaped like a file is rebuilt only as an HTTP(S) URL with force_download reset, and an UploadedFile or non-HTTP URL stays a mapping. This also applies to files your own tools returned before the upgrade: in history saved by an earlier version, a tool-returned UploadedFile, non-HTTP URL, or force_download setting does not survive loading. Files saved by the patched version keep every field.
If you stored that history yourself and trust its contents, load it with ModelMessagesTypeAdapter.validate_json(data, context={‘pydantic_ai’: {‘rebuild_unrecorded_tool_files’: True}}) (or validate_python), and its file items load as they did before. Save it again, and it carries the record and no longer needs the context. Only do this for history no third party could have shaped: loading it this way restores the earlier behavior for any lookalike it already contains.
Older versions ignore the record, so a rolling upgrade of durable-execution workers is safe, and durable execution decodes journal entries written before the upgrade as before, so runs in flight keep their files. The harness’s step persistence stores, saved conversations, and delegated-task records likewise load snapshots saved before the upgrade as before, so continued and forked runs keep their files. If those journals or snapshots may contain tool results built from third-party data, finish or discard runs started before the upgrade rather than continuing them, or run sanitize_messages() on the history first.
No exploitation in the wild is reported in the sources.
Sources:
- GitHub Security Advisory GHSA-4cj4-hgwf-4hc4
- NVD CVE-2026-133505
This is the second Pydantic AI advisory we have covered this week, after the Pydantic AI Harness event loop flaw. Untrusted data flowing into agents through tools is a recurring risk across the Agents section, and new cases are tracked in our AI Security hub.
Sources
- GitHub Security Advisory GHSA-4cj4-hgwf-4hc4
- NVD CVE-2026-133505



