Описание
FastMCP OpenAPI Provider has an SSRF & Path Traversal Vulnerability
Technical Description
The OpenAPIProvider in FastMCP exposes internal APIs to MCP clients by parsing OpenAPI specifications. The RequestDirector class is responsible for constructing HTTP requests to the backend service.
A critical vulnerability exists in the _build_url() method. When an OpenAPI operation defines path parameters (e.g., /api/v1/users/{user_id}), the system directly substitutes parameter values into the URL template string without URL-encoding. Subsequently, urllib.parse.urljoin() resolves the final URL.
Since urljoin() interprets ../ sequences as directory traversal, an attacker controlling a path parameter can perform path traversal attacks to escape the intended API prefix and access arbitrary backend endpoints. This results in authenticated SSRF, as requests are sent with the authorization headers configured in the MCP provider.
Vulnerable Code
File: fastmcp/utilities/openapi/director.py
Root Cause
- Path parameters are substituted directly without URL encoding
urllib.parse.urljoin()interprets../as directory traversal- No validation prevents traversal sequences in parameter values
- Requests inherit the authentication context of the MCP provider
Proof of Concept
Step 1: Backend API Setup
Create internal_api.py to simulate a vulnerable backend server:
Step 2: Exploitation Script
Create exploit_poc.py:
Expected Output
The attacker successfully accessed an endpoint not defined in the OpenAPI specification using the MCP provider's authentication credentials.
Impact Assessment
Severity Justification
- Unauthorized Access: Attackers can interact with private endpoints not exposed in the OpenAPI specification
- Privilege Escalation: The attacker operates within the MCP provider's security context and credentials
- Authentication Bypass: The primary security control of OpenAPIProvider (restricting access to safe functions) is completely circumvented
- Data Exfiltration: Sensitive internal APIs can be accessed and exploited
- Lateral Movement: Internal-only services may be compromised from the network boundary
Attack Scenarios
- Accessing Admin Panels: Bypass API restrictions to reach administrative endpoints
- Data Theft: Access internal databases or sensitive information endpoints
- Service Disruption: Trigger destructive operations on backend services
- Credential Extraction: Access endpoints returning API keys, tokens, or credentials
Remediation
Recommended Fix
URL-encode all path parameter values before substitution to ensure reserved characters (/, ., ?, #) are treated as literal data, not path delimiters.
Updated code for _build_url() method:
Ссылки
- https://github.com/PrefectHQ/fastmcp/security/advisories/GHSA-vv7q-7jx5-f767
- https://nvd.nist.gov/vuln/detail/CVE-2026-32871
- https://github.com/PrefectHQ/fastmcp/pull/3507
- https://github.com/PrefectHQ/fastmcp/commit/40bdfb6b1de0ce30609ee9ba5bb95ecd04a9fb71
- https://github.com/PrefectHQ/fastmcp/releases/tag/v3.2.0
Пакеты
fastmcp
< 3.2.0
3.2.0
Связанные уязвимости
FastMCP is a Pythonic way to build MCP servers and clients. Prior to version 3.2.0, the OpenAPIProvider in FastMCP exposes internal APIs to MCP clients by parsing OpenAPI specifications. The RequestDirector class is responsible for constructing HTTP requests to the backend service. A vulnerability exists in the _build_url() method. When an OpenAPI operation defines path parameters (e.g., /api/v1/users/{user_id}), the system directly substitutes parameter values into the URL template string without URL-encoding. Subsequently, urllib.parse.urljoin() resolves the final URL. Since urljoin() interprets ../ sequences as directory traversal, an attacker controlling a path parameter can perform path traversal attacks to escape the intended API prefix and access arbitrary backend endpoints. This results in authenticated SSRF, as requests are sent with the authorization headers configured in the MCP provider. This issue has been patched in version 3.2.0.
FastMCP is a Pythonic way to build MCP servers and clients. Prior to version 3.2.0, the OpenAPIProvider in FastMCP exposes internal APIs to MCP clients by parsing OpenAPI specifications. The RequestDirector class is responsible for constructing HTTP requests to the backend service. A vulnerability exists in the _build_url() method. When an OpenAPI operation defines path parameters (e.g., /api/v1/users/{user_id}), the system directly substitutes parameter values into the URL template string without URL-encoding. Subsequently, urllib.parse.urljoin() resolves the final URL. Since urljoin() interprets ../ sequences as directory traversal, an attacker controlling a path parameter can perform path traversal attacks to escape the intended API prefix and access arbitrary backend endpoints. This results in authenticated SSRF, as requests are sent with the authorization headers configured in the MCP provider. This issue has been patched in version 3.2.0.