T09 · Insecure Skill Coding Practices
- Location
scripts/clone_style.py:16- Finding
OpenAI API Credential May Be Disclosed to an Unintended Provider
- Content
View full analysis
str: if not API_KEY: return "[错误] 请设置环境变量 OPENAI_API_KEY 或 DEEPSEEK_API_KEY" payload = json.dumps({ "model": MODEL, "messages": [ { "role": "system", "content": ( "你是一位顶级的文字风格分析师和创意写作专家。" "你能精准捕捉任何作者的写作风格,并将其复制到新的内容上。" "你的改写保留原素材的核心信息和观点,同时完美呈现目标风格。" "请用中文输出。" ) }, {"role": "user", "content": prompt} ], "temperature": 0.85, }).encode("utf-8") req = urllib.request.Request( f"{API_BASE}/chat/completions", data=payload, headers={ "Content-Type": "application/json", "Authorization": f"Bearer {API_KEY}", } ) with urllib.request.urlopen(req, timeout=90) as r: data = json.loads(r.read()) return data["choices"][0]["message"]["content"] ``` ### Technical Analysis Credential selection and endpoint selection are performed independently. `OPENAI_API_KEY` has precedence whenever it is present, but the default API endpoint is `https://api.deepseek.com`. Therefore, when a user configures `OPENAI_API_KEY` without also configuring `OPENAI_API_BASE`, the program places the OpenAI credential in an HTTP Authorization header and sends it to DeepSeek. This is a provider-confusion flaw. A secret intended for one service must not be transmitted to another service based on an unrelated endpoint default. The project documentation explicitly permits ...[truncated 1973 chars]- Remediation
View remediation
