T09 · Insecure Skill Coding Practices
- Location
mcp_client.py:17- Finding
Bearer API Credentials May Be Transmitted over Plaintext HTTP
- Content
View full analysis
Vulnerability Details
File Location:
mcp_client.py, lines 17–25
Vulnerability Type: Transmission of sensitive information over an insecure channel
Risk Level: MediumVulnerable Code
python DEFAULT_MCP_SERVER = "http://localhost:8080" class MCPClient: """Client for Model Context Protocol""" def __init__(self, server_url=DEFAULT_MCP_SERVER, api_key=None): self.server_url = server_url.rstrip("/") self.session = requests.Session() if api_key: self.session.headers["Authorization"] = f"Bearer {api_key}"The server URL is user-configurable, and the client does not require HTTPS before adding the supplied API key to the session's
Authorizationheader. Although the default endpoint is a loopback address, callers can provide a non-loopbackhttp://endpoint without receiving a warning or having the request rejected.Technical Analysis
Bearer tokens grant access to whoever possesses them. When the client communicates with a remote server over plaintext HTTP, the authorization header is not protected by transport encryption. An attacker with visibility or control over the network path can inspect or modify the request and recover the API key.
TLS certificate verification is enabled by default in
requestsfor HTTPS endpoints, but this protection does not apply when the configured URL uses HTTP. The issue therefore becomes exploitable when a user supplies an API key together with a plaintext, non-loopback server URL.Attack Path
- A user is instructed to connect to a remote MCP endpoint using an
http://URL. - The user supplies an API key to
MCPClientor through the CLI. - The constructor places the key in the session-wide
Authorization: Bearerheader. - A client method sends a request to the plaintext endpoint.
- An attacker controlling or observing the network path captures the authorization header.
- The attacke ...[truncated 431 chars]
- A user is instructed to connect to a remote MCP endpoint using an
- Remediation
View remediation
Remediation Suggestions
- Require an
https://URL whenever an API key is configured. - Allow plaintext HTTP only for explicitly recognized loopback addresses, such as
127.0.0.1,::1, andlocalhost. - If remote plaintext access is operationally necessary, require an explicit option such as
--allow-insecure-httpand display a prominent warning. - Parse and validate the URL with
urllib.parse.urlparseinstead of relying on string-prefix checks. - Continue using the default TLS certificate verification behavior and do not introduce a general certificate-verification bypass.
- Avoid forwarding authorization headers if future code permits redirects to a different origin; explicitly constrain redirects or reject cross-origin redirects for authenticated requests.
- Require an
