Summary
FastMCP's OpenAPIProvider incorrectly substitutes unencoded path parameters into backend URLs, allowing attackers to manipulate request paths via directory traversal sequences.
When an attacker controls a path parameter in an OpenAPI-described endpoint, they can escape the intended API prefix and trigger authenticated SSRF requests to arbitrary internal backend endpoints.
Affected context
This vulnerability appears in FastMCP deployments that:
- Use the OpenAPIProvider to expose backend HTTP APIs to MCP clients
- Rely on OpenAPI specifications with templated path parameters (e.g.,
/api/v1/users/{user_id}) - Have backend services reachable from the MCP server that are not directly accessible to the client
- Attach authentication or authorization headers to outbound requests from the MCP provider
The risk materializes when MCP clients can influence path parameter values that are used to construct backend URLs without additional validation or encoding.
Exploit preconditions
- Attack surface: MCP API endpoints defined via OpenAPI that include path parameters.
- Required access: Ability for an attacker-controlled MCP client (or a compromised client) to invoke operations with attacker-chosen path parameter values.
- Trigger point: Invocation of an OpenAPI operation where the RequestDirector's
_build_url()method substitutes user-controlled values into a URL template and then passes it throughurllib.parse.urljoin(). - Why exploitation is possible: Path parameter values are inserted into the URL without URL-encoding or path normalization checks.
urljoin()treats../sequences as directory traversal, allowing the constructed URL to escape the intended base path and target arbitrary internal endpoints while still carrying configured authorization headers.
Why this happens
The core issue lies in how the RequestDirector's _build_url() method constructs backend URLs from OpenAPI templates. Instead of treating path parameters as data that must be encoded, the implementation directly interpolates raw parameter values into the URL path prior to calling urllib.parse.urljoin().
Because urljoin() implements URL resolution semantics, it processes ../ segments as directory traversal operations on the path. An attacker who controls a path parameter can therefore introduce ../ sequences or other path-manipulating constructs to override or escape the intended API base path chosen by the MCP provider.
This behavior maps to CWE-918: Server-Side Request Forgery (SSRF), where a server-side component builds and issues HTTP requests based on attacker-controlled input. The lack of URL-encoding and path validation allows the attacker to pivot the server into contacting internal resources on their behalf, using the server's network position and authorization context.
Potential impact
- MCP server may send authenticated requests to unintended internal backend endpoints.
- Attackers could access or enumerate internal APIs that are not exposed to external clients.
- Sensitive data from internal services may be returned to the attacker-controlled client.
- Internal state of backend services could be modified via forged requests.
- Potential pivot to further vulnerabilities in internal services (e.g., injection, misconfiguration, debug endpoints).
- Abuse of privileged authorization headers configured for the MCP provider to bypass normal access controls.
General mitigation guidance
Effective mitigations focus on treating URL components as data, constraining backend reachability, and validating derived request targets:
- Strictly encode path parameters: Always URL-encode path parameter values before interpolating them into URL paths so that special characters like
/,?,#, and..are treated as data rather than path control. - Normalize and validate final URLs: After constructing a URL, normalize the path and validate that it still resides under the intended API prefix or allowed path set before sending the request.
- Constrain allowed destinations: Enforce a strict allowlist of backend hosts and base paths that the provider is permitted to contact, rejecting any request that resolves outside those boundaries.
- Separate authorization scopes: Avoid reusing powerful authorization headers for generic routing logic; scope credentials to the minimal set of endpoints needed and avoid "catch-all" tokens with broad access.
- Reduce trust in client-provided parameters: Treat all client-influenced path parameters as untrusted input and apply length, character, and pattern constraints before using them in request construction.
- Defense-in-depth at backend: Configure backend services to enforce their own authorization and path restrictions, assuming that upstream routing layers can be bypassed or misconfigured.
How teams detect issues like this
Detection should target both insecure URL construction patterns in code and anomalous backend traffic:
- Static analysis and code scanning:
- Flag code that directly interpolates user-controlled variables into URL strings without encoding.
- Detect uses of
urllib.parse.urljoin()or similar resolvers where either argument contains untrusted input, especially when used with a base path prefix. - Identify functions responsible for HTTP routing that lack explicit allowlists, normalization, or validation of outbound URLs.
- Targeted code review:
- Review the RequestDirector and similar request-building abstractions for correct use of URL-encoding routines.
- Check that all OpenAPI-derived path parameters are treated as untrusted and are validated or constrained.
- Inspect how authorization headers are attached to outbound requests and ensure they are not universally applied to all internal destinations.
- Runtime monitoring and logging:
- Log final resolved URLs for MCP-to-backend requests and alert on suspicious patterns, such as repeated
../sequences or unexpected service paths. - Monitor for unusual access from the MCP server to internal endpoints that are not part of the documented API surface.
- Policy enforcement:
- Use HTTP proxies, service meshes, or network policies to restrict which internal endpoints the MCP server can reach, logging and blocking attempts to contact out-of-scope paths or hosts.
- Integrate automated review tools in CI/CD pipelines to enforce URL-construction best practices and prevent reintroduction of similar patterns.

