Summary
A Server-Side Request Forgery (SSRF) issue in Pydantic AI's URL download functionality allows untrusted message history to trigger HTTP requests from the server to arbitrary URLs.
If an application accepts message history from external users, an attacker can embed malicious URLs that cause the backend to reach internal network resources, potentially exposing internal services or cloud metadata and credentials.
Affected context
This vulnerability affects applications built with Pydantic AI (versions 0.0.26 to before 1.56.0) that:
- Use the framework's URL download or fetching capabilities as part of agent workflows, and
- Accept message history or similar conversational state from untrusted or external users, and
- Allow those messages to influence which URLs the server requests.
It does not inherently affect deployments where message history is fully controlled, sanitized, or generated exclusively by trusted backend components.
Exploit preconditions
- Attack surface: Pydantic AI–based endpoints or workflows that accept externally supplied message history or user content that can contain or influence URLs.
- Required access: Ability to send messages or payloads that the application ingests as conversation history for the agent.
- Trigger point: Invocation of the URL download functionality when processing the user-controlled history, causing the server to issue HTTP requests to attacker-chosen URLs.
- Why exploitation is possible: The URL download logic treats user-influenced URLs as trustworthy and does not sufficiently restrict or validate the destination, allowing access to internal or otherwise non-public endpoints from the server's network position.
Why this happens
The core issue stems from treating user-controlled or user-influenced URLs as safe targets for server-side HTTP requests without applying robust validation or network egress controls.
This aligns with CWE-918: Server-Side Request Forgery (SSRF), where backend functionality makes outbound network calls based on untrusted input, effectively turning the server into a proxy into its own internal network and cloud environment.
Conceptually, the agent workflow couples:
- Conversational inputs (message history) that may contain arbitrary URLs, with
- A powerful server-side HTTP client capable of reaching internal services, metadata endpoints, or management interfaces.
Without strict allowlists or blocking of sensitive address ranges (e.g., 169.254.169.254, RFC1918 networks), an attacker's URLs can traverse network boundaries that are not directly reachable from the internet.
Potential impact
- Access to internal HTTP-based services that are not exposed publicly.
- Discovery of internal network structure and service endpoints.
- Retrieval of cloud instance metadata, which may include temporary credentials or tokens.
- Abuse of internal APIs, potentially leading to data exfiltration or configuration changes.
- Use of the server as a pivot point for further attacks inside the private network.
General mitigation guidance
Effective mitigation focuses on treating all external URLs as untrusted and constraining where the server is allowed to connect:
- Prefer explicit allowlists of domains or URL patterns that the application is permitted to fetch, rather than filtering out "bad" destinations.
- Reject or sanitize URLs that resolve to:
- Private IP ranges (e.g., 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16),
- Link-local or metadata endpoints (e.g., 169.254.169.254),
- Localhost and loopback addresses (127.0.0.0/8, ::1) and the server's own IPs.
- Resolve hostnames and validate the final destination after DNS resolution, not just the hostname string.
- Decouple user-visible messaging or "history injection" features from any direct URL fetching, e.g., by requiring a trusted backend decision point before performing outbound requests.
- Apply network-level egress controls (firewalls, security groups, service mesh policies) to block or tightly limit access to sensitive internal and metadata endpoints from the application runtime.
- Run URL fetch logic with least-privilege network and cloud permissions, ensuring that even if SSRF is attempted, there is minimal access to high-value resources.
How teams detect issues like this
Detection generally involves a combination of code-level inspection and runtime monitoring:
- Static analysis and code review:
- Search for HTTP client usage in Pydantic AI workflows or tools that accept URLs influenced by user or external message history.
- Flag patterns where user content is passed directly into URL download helpers without validation or allowlisting.
- Review any "agent tools" or "actions" that perform network calls, verifying they apply domain and IP safeguards.
- Policy enforcement:
- Introduce coding guidelines that prohibit direct use of generic URL-fetch APIs with untrusted input.
- Use automated code scanning tools to enforce network egress rules or to detect missing URL validation wrappers.
- Runtime monitoring:
- Log outbound HTTP requests with destination host/IP and correlate them with request context or user identity.
- Alert on connections to unusual destinations, especially private IP spaces, metadata endpoints, or new internal services.
- Use network-level observability (service mesh, firewall logs) to detect and investigate suspicious outbound patterns from Pydantic AI services.

