T09 · Insecure Skill Coding Practices
- Location
scripts/visual.py:174- Finding
User-configured API endpoints allow plaintext transmission of credentials and sensitive media
- Content
View full analysis
str: """调用 OpenAI 兼容 API(带重试)""" payload = {"model": model, "messages": messages, "max_tokens": 6000, "temperature": 0.3} req_data = json.dumps(payload).encode("utf-8") req = urllib.request.Request( f"{api_base.rstrip('/')}/chat/completions", data=req_data, headers={"Content-Type": "application/json", "Authorization": f"Bearer {api_key}"} ) resp_data = http_request_with_retry(req, timeout=180, label=f"Vision LLM ({model})") ``` The same pattern is used for audio: ```python url = f"{api_base.rstrip('/')}/audio/transcriptions" req = urllib.request.Request( url, data=body, headers={"Content-Type": f"multipart/form-data; boundary={boundary}", "Authorization": f"Bearer {api_key}"} ) ``` And for metadata synthesis: ```python req = urllib.request.Request( f"{api_base.rstrip('/')}/chat/completions", data=json.dumps(payload).encode('utf-8'), headers={"Content-Type":"application/json","Authorization":f"Bearer {api_key}"} ) ``` ### Technical Analysis The scripts accept an arbitrary API base URL and append an API path without parsing or validating the URL scheme. Consequently, an endpoint beginning with `http://` is accepted. These requests include a bearer API key and one or more sensitive content types: - Encoded video frames - Extracted audio - Complete transcripts - Derived visual observations - Generated publishing metadata Base64 encoding in `visual.py` and `transcribe.py` is normal API serialization and is not encryption. If the configured endpoint uses pla ...[truncated 1554 chars]- Remediation
View remediation
str: parsed = urlparse(api_base) local_hosts = {"localhost", "127.0.0.1", "::1"} if parsed.scheme == "https" and parsed.hostname: return api_base.rstrip("/") if ( allow_insecure_localhost and parsed.scheme == "http" and parsed.hostname in local_hosts ): return api_base.rstrip("/") raise ValueError("API endpoint must use HTTPS") ``` Apply this validation consistently in `visual.py`, `transcribe.py`, and `analyze.py`. ]]>
