Summary
A path traversal flaw in the Pydantic AI web UI's CDN URL construction allows an attacker to inject arbitrary JavaScript into the application's browser context via a crafted URL.
By abusing an unvalidated version query parameter, an attacker can cause the server to serve attacker-controlled HTML/JS from the CDN, leading to theft of chat history and other client-side data when a victim loads the malicious link.
Affected context
This vulnerability affects applications that:
- Use
Agent.to_webto expose a chat UI, or - Use the
clai webcommand to run a chat interface from the CLI.
In these setups, the server-side handler constructs a CDN URL for the chat UI assets based on a version query parameter from the incoming HTTP request. Because this parameter is not validated or normalized, an attacker can embed path traversal sequences that cause the server to pull and relay HTML/JS from an unintended location on the same CDN. The issue manifests whenever users open untrusted links to the affected web UI, whether hosted on localhost or on a remote server.
Exploit preconditions
- Attack surface: HTTP interface of the Pydantic AI web UI (Agent.to_web or
clai web). - Required access: Ability to convince a victim to visit a crafted URL (e.g., link sharing, phishing, iframe embedding); no prior authentication is inherently required by the vulnerability itself.
- Trigger point: A malicious request containing a specially crafted
versionquery parameter that induces path traversal in the constructed CDN asset URL. - Why exploitation is possible: The server trusts the
versionparameter, concatenates it into the CDN path without validation or canonicalization, and then fetches and serves the resulting resource. This enables an attacker to redirect the asset load to attacker-controlled HTML/JS already present on the same CDN, which then runs in the trusted origin of the chat UI.
Why this happens
The underlying issue is improper input handling in URL construction combined with implicit trust in remotely loaded resources.
The web UI code takes a version query parameter from the request and interpolates it into the CDN asset path without:
- Validating it against an allowlist of expected version formats, or
- Normalizing the path to prevent
../-style traversal.
This maps to CWE-22: Path Traversal because untrusted input is used to navigate within a remote resource hierarchy. The resulting behavior leads to CWE-79-like impact because the server ends up proxying attacker-selected HTML/JavaScript that executes in the victim's browser under the application's origin. Conceptually, this is a client-side code injection problem caused by server-side URL composition that fails to constrain the resource location.
Potential impact
- Theft of chat history and other sensitive data stored in the browser for the affected Pydantic AI interface.
- Exfiltration of API keys, tokens, or configuration data exposed in the web UI or stored in local/session storage.
- Impersonation of the user within the chat session, including sending or modifying messages on their behalf.
- Injection of misleading or malicious UI elements, potentially tricking users into revealing additional sensitive information.
- Use of the compromised browser context as a pivot to attempt further attacks within the same origin or adjacent application features.
General mitigation guidance
Effective mitigation focuses on constraining how remote assets are addressed and reducing trust in client-supplied parameters:
- Restrict and validate version parameters:
- Treat version identifiers as data, not paths—enforce a strict pattern (e.g., semantic version or short tag) and reject any value containing slashes, traversal sequences, or URL control characters.
- Prefer an explicit allowlist of known-good versions when dynamic selection is required.
- Avoid raw concatenation for URL paths:
- Use structured URL builders or path-joining utilities that operate on validated tokens rather than raw string concatenation.
- Normalize and canonicalize paths before use, and fail closed on any attempt to escape an expected directory.
- Limit the scope of remote content loading:
- Constrain asset fetching to fixed, known paths on the CDN and keep the asset identifier separate from the directory structure.
- Avoid serving arbitrary HTML content fetched based on user-controlled parameters; fetch static assets whose location is pre-determined.
- Harden the browser environment where possible:
- Apply security headers such as Content Security Policy (CSP) to restrict script execution sources, reducing the impact of unintended HTML/JS being served.
- Minimize sensitive data stored in the browser and ensure that secrets or credentials are not exposed in the front-end unless strictly necessary.
- Apply least-privilege design for UI data:
- Only expose the minimum data required for the chat interface to function, and keep sensitive operational or debugging information out of the client.
How teams detect issues like this
Detection is best approached through a mix of code analysis, configuration review, and behavioral monitoring:
- Static analysis and code review:
- Search for instances where query parameters (e.g.,
version) are concatenated into URLs or file paths without validation. - Flag patterns where user input is used in CDN or asset URLs, especially when combined with
../or other path-like constructs. - Review web UI routing and asset-serving handlers to ensure they do not proxy arbitrary HTML/JS based on request parameters.
- Automated security scanning:
- Use dynamic application security testing (DAST) tools to probe for path traversal via query parameters and to detect unexpected HTML/JS served when parameters contain traversal sequences.
- Integrate URL and parameter sanitization checks into CI/CD pipelines to catch unsafe patterns early.
- Runtime monitoring:
- Log full request paths and selected query parameters for the web UI endpoints, and alert on anomalous versions containing slashes or traversal patterns.
- Monitor for unusual asset fetch patterns to the CDN from the application, such as requests for non-standard or unexpected paths.
- Policy and coding standards:
- Establish guidelines that prohibit using unvalidated client input for path or URL construction.
- Encourage use of centralized helpers for safe URL/path generation so deviations are easier to spot and audit.

