T09 · Insecure Skill Coding Practices
- Location
mcp_client.py:16- Finding
API Credentials May Be Exposed Through Plaintext HTTP and Command-Line Arguments
- Content
View full analysis
Vulnerability Details
File Location:
mcp_client.py:16-31,mcp_client.py:108-109, andSKILL.md:27
Vulnerability Type: Insecure transport and sensitive credential exposure
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}" def connect(self): """Connect to MCP server""" resp = self.session.get(f"{self.server_url}/mcp/connect") resp.raise_for_status() return resp.json()python parent_parser.add_argument("--server-url", default=DEFAULT_MCP_SERVER, help="MCP Server URL") parent_parser.add_argument("--api-key", help="API Key")The documented invocation also places the API key in a command-line argument:
powershell .\mcp.ps1 -Action connect -ServerUrl "https://mcp-server.com" -ApiKey "your-key"Technical Analysis
The client accepts arbitrary server URLs without validating their scheme or requiring TLS. When an API key is supplied, it is installed as a Bearer token in the session's
Authorizationheader and sent to the configured endpoint. Although the default HTTP endpoint is loopback-only, a user can provide a non-loopbackhttp://URL, causing the credential and subsequent MCP traffic to be transmitted without transport encryption.The CLI additionally accepts the API key directly through
--api-key, while the documentation recommends a corresponding command-line credential argument. Command-line secrets may be exposed through shell history, process inspection facilities, diagnostic tooling, terminal recordings, or command logging.Attack Path
...[truncated 1180 chars]
- Remediation
View remediation
Remediation Suggestions
- Require
https://for all non-loopback MCP endpoints. Reject plaintext HTTP rather than merely documenting the risk. - If local HTTP support is necessary, permit it only for explicitly recognized loopback addresses such as
localhost,127.0.0.1, and::1. - Validate the parsed URL before constructing the client session, including its scheme and hostname.
- Remove or deprecate direct API-key command-line arguments.
- Read credentials from a protected environment variable, operating-system credential store, restricted configuration file, or interactive hidden prompt.
- Avoid including credentials in logs and exception messages, and redact authorization data from diagnostic output.
- Document secure credential provisioning and warn users not to place secrets in shell history.
- Apply narrowly scoped, short-lived API credentials and support credential rotation to limit the consequences of disclosure.
- Require
