T09 · Insecure Skill Coding Practices
- Location
scripts/ai_engine.py:29- Finding
OpenAI API credentials may be transmitted to the DeepSeek endpoint
- Content
View full analysis
Vulnerability Details
File Location:
scripts/ai_engine.py:29-59, 75-108
Vulnerability Type: Cross-provider credential disclosure
Risk Level: CriticalVulnerable Code
python def _resolve_api_key(): """解析API Key,优先DeepSeek""" # 1. DeepSeek环境变量 ds_env = os.environ.get("DEEPSEEK_API_KEY", "") if ds_env: return ds_env # 2. OpenClaw配置中的DeepSeek Key _cfg_path = os.path.expanduser("~/.openclaw/openclaw.json") if os.path.exists(_cfg_path): try: with open(_cfg_path) as _f: _cfg = json.load(_f) _providers = _cfg.get("models", {}).get("providers", {}) _key = _providers.get("deepseek", {}).get("apiKey", "") if _key: return _key except: pass # 3. 降级到OpenAI(但仅当key不是sk-proj-格式时才用) oa_env = os.environ.get("OPENAI_API_KEY", "") if oa_env and not oa_env.startswith("sk-proj-"): return oa_env return "" AI_API_KEY = _resolve_api_key() AI_BASE_URL = "https://api.deepseek.com/v1" AI_MODEL = "deepseek-chat"python api_key = AI_API_KEY base_url = AI_BASE_URL model = AI_MODEL if not api_key: return "⚠️ 未找到AI API Key,请配置 DEEPSEEK_API_KEY 或 OPENAI_API_KEY" if "deepseek" in model: system_prompt = system_prompt.replace("【", "<").replace("】", ">") payload = { "model": model, "messages": [ {"role": "system", "content": system_prompt}, {"role": "user", "content": user_prompt}, ], "temperature": temperature, "max_tokens": max_tokens, } data = json.dumps(payload).encode("utf-8") req = urllib.request.Request( f"{base_url}/chat/completions", data=data, headers={ "Content-Type": "application/json", "Authorization": f"Bearer {api_key}", }, method="POST", ) try: ...[truncated 2015 chars]- Remediation
View remediation
Remediation Suggestions
- Remove the
OPENAI_API_KEYfallback unless the request is also switched to the official OpenAI endpoint and a compatible OpenAI model. - Resolve provider configuration as an inseparable structure containing:
- provider name;
- API key;
- base URL;
- model name.
- Reject configurations in which the selected credential type does not match the selected endpoint.
- Prefer an explicit provider setting rather than inferring the provider from available secrets.
- Use separate functions or typed configuration objects for DeepSeek and OpenAI requests.
- Add tests confirming that OpenAI credentials can never appear in requests to DeepSeek domains.
- Rotate any OpenAI key that may already have been processed by this implementation.
- Remove the
