Summary
Claude Code used a naive prefix-based string check to validate "trusted" domains for WebFetch requests, allowing lookalike domains such as modelcontextprotocol.io.example.com to be treated as trusted.
If an attacker can lure the tool or user into fetching from such a crafted domain, the tool may automatically send requests to attacker-controlled servers without explicit user consent, which can expose sensitive data.
Affected context
This vulnerability affects workflows in Claude Code that rely on WebFetch requests to a fixed set of "trusted" domains (for example documentation or protocol endpoints).
The issue arises when trust is inferred solely from a URL string starting with a known domain substring, rather than from strict hostname and scheme validation.
In environments where the tool holds or can access sensitive project data, automatically following such misvalidated URLs increases the risk that private information is sent to attacker-controlled infrastructure.
Exploit preconditions
- Attack surface: Outbound WebFetch requests performed by Claude Code.
- Required access: Ability to influence or control the URLs that the tool is asked to fetch (e.g., through prompts, shared snippets, project configuration, or embedded links).
- Trigger point: WebFetch is invoked for a URL whose hostname is crafted to start with a trusted domain string, such as
docs.python.org.evil.comormodelcontextprotocol.io.attacker.org. - Why exploitation is possible: The validation logic uses
startsWith()on the URL string to decide whether a destination is "trusted," which does not enforce boundaries between hostnames. This allows attacker-controlled domains that merely share a prefix with a trusted domain to be incorrectly accepted.
Why this happens
The underlying bug is an improper validation of URLs against a trusted-domain allowlist, aligned with CWE-601: URL Redirection to Untrusted Site ('Open Redirect') patterns.
Instead of parsing the URL and comparing the normalized hostname and scheme against an exact or well-scoped set of allowed origins, the implementation relied on startsWith() string comparison.
This ignores domain boundaries, subdomain relationships, and potential URL encoding edge cases.
As a result, attacker-registered domains that simply begin with the trusted domain text are treated as if they belong to the trusted set, causing the tool to send requests to untrusted endpoints while believing they are safe.
Potential impact
- Claude Code may send HTTP requests to attacker-controlled domains that masquerade as trusted hosts.
- Sensitive project content, snippets, or contextual data associated with a WebFetch operation could be exfiltrated.
- Attackers could collect metadata about usage patterns, project structure, or connected services.
- Downstream attacks such as phishing, targeted social engineering, or dependency confusion may be facilitated through harvested information.
General mitigation guidance
Effective mitigation focuses on robust URL and origin validation rather than string-prefix checks:
- Parse URLs using a dedicated, well-tested URL parsing library and validate based on structured components (scheme, hostname, port).
- Compare hostnames against an explicit allowlist using exact matches or carefully scoped subdomain rules (e.g., checking registrable domains via public suffix lists when subdomains are allowed).
- Normalize and canonicalize URLs before validation to avoid bypasses due to encoding, casing, or trailing-dot tricks.
- Restrict the amount and sensitivity of data automatically attached to outbound WebFetch requests, following least-privilege and data minimization principles.
- Introduce user confirmation or explicit consent when WebFetch is directed to domains that are not clearly in a conservative trusted set.
How teams detect issues like this
Organizations can look for this class of issue by:
- Performing static analysis or code search for domain validation that relies on
startsWith(),contains(), or similar substring checks instead of parsed host comparisons. - Reviewing code paths around outbound HTTP requests for simplistic allowlist logic or direct string comparison with trusted domains.
- Implementing security review checklists that flag any trust decision based purely on URL string prefixes or suffixes.
- Using automated security scanning tools that understand URL/host validation anti-patterns and highlight potential improper redirects or domain checks.
- Logging and periodically reviewing outbound request destinations to detect unexpected domains that visually resemble trusted services.

