T09 · Insecure Skill Coding Practices
- Location
scripts/tts.py:151- Finding
Unrestricted API Endpoint Override Can Disclose API Credentials and Voice Samples
- Content
View full analysis
bytes: data = json.dumps(payload).encode() req = urllib.request.Request( f"{API_BASE}/chat/completions", data=data, headers={"Content-Type": "application/json", "api-key": api_key}, method="POST", ) ``` Clone mode reads and Base64-encodes the user-selected voice sample: ```python def _read_clone_audio(path: str) -> Tuple[str, str]: if not os.path.exists(path): raise TtsError(f"音频文件不存在: {path}") suffix = os.path.splitext(path)[1].lower() mime_map = {".mp3": "audio/mpeg", ".wav": "audio/wav"} mime = mime_map.get(suffix) if not mime: raise TtsError(f"不支持的音频格式: {suffix},仅支持 mp3/wav") with open(path, "rb") as f: voice_bytes = f.read() if len(voice_bytes) > 10 * 1024 * 1024: raise TtsError("音频文件过大(最大 10 MB)") voice_b64 = base64.b64encode(voice_bytes).decode("utf-8") return f"data:{mime};base64,{voice_b64}", mime ``` The command-line interface also permits an unrestricted endpoint override: ```python parser.add_argument("--base-url", default=None, help="自定义 API 端点 URL(覆盖 MIMO_API_BASE 环境变量)") args = parser.parse_args() if args.base_url: global API_BASE API_B ...[truncated 4675 chars]- Remediation
View remediation
