T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/gen.py:237
- Finding
- TLS Certificate Verification Disabled for Credential-Bearing API Requests## Vulnerability Details **File Location**: `scripts/gen.py`, lines 237-245 **Vulnerability Type**: Improper TLS certificate validation **Risk Level**: High ### Vulnerable Code ```python ctx = ssl.create_default_context() ctx.check_hostname = False ctx.verify_mode = ssl.CERT_NONE data = json.dumps(payload).encode("utf-8") try: req = urllib.request.Request(url, data=data, headers=headers, method="POST") with urllib.request.urlopen(req, context=ctx, timeout=120) as response: ``` The request headers constructed earlier contain the MiniMax API credential: ```python headers = { "Authorization": f"Bearer {self.api_key}", "Content-Type": "application/json", } ``` ### Technical Analysis The code creates a standard TLS context but then explicitly disables hostname checking and certificate verification. Consequently, the client does not verify that the remote endpoint presenting a certificate is the legitimate `api.minimaxi.com` service. The affected request carries the MiniMax API key in a bearer authorization header and includes the user's image prompt in its JSON body. HTTPS encryption alone does not provide endpoint authenticity when certificate validation is disabled. An attacker capable of intercepting or redirecting network traffic can present an arbitrary certificate, terminate the TLS connection, and receive both the credential and prompt. Sending the API key to the documented MiniMax API is necessary for the declared image-generation functionality. Disabling TLS verification is unnecessary and exceeds the minimum acceptable security posture for transmitting that secret. ### Attack Path 1. A user invokes the Skill to generate an image. 2. The Skill creates a POST request containing the bearer API key and user prompt. 3. An attacker with a network interception position, malicious proxy, or DNS-routing capability redirects the connection to an attacker-controlled endpoint. 4. The ...[truncated 977 chars]
- Remediation
- ## Remediation Suggestions Preserve the secure defaults provided by Python's TLS implementation. Remove both overrides: ```python ctx = ssl.create_default_context() req = urllib.request.Request(url, data=data, headers=headers, method="POST") with urllib.request.urlopen(req, context=ctx, timeout=120) as response: result = json.loads(response.read().decode("utf-8")) ``` Additional hardening should include: - Never add an automatic fallback that disables certificate validation after a TLS error. - If a private trust chain is genuinely required, load a narrowly scoped and trusted CA bundle with `SSLContext.load_verify_locations()` rather than disabling verification. - Keep the API destination fixed to the documented HTTPS endpoint. - Avoid including secrets or complete server response bodies in error output. - Add a test confirming that untrusted, expired, and hostname-mismatched certificates are rejected. - Rotate the API key if the vulnerable implementation has been used on an untrusted network.
