T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/evolver_core.py:301
- Finding
- Unrestricted API Endpoint Receives Raw Task Inputs and Execution Context<![CDATA[ ## Vulnerability Details **File Location**: `scripts/evolver_core.py:301-362`; related input flow in `scripts/evolution_cli.py:31-51` **Vulnerability Type**: Sensitive-data disclosure to an unrestricted network endpoint **Risk Level**: High ### Vulnerable Code ```python class LLMIntegration: """LLM integration for error analysis and solution generation""" def __init__(self, api_key: str = None, model: str = "gpt-3.5-turbo"): self.api_key = api_key or os.getenv("OPENAI_API_KEY") self.model = model self.api_base = os.getenv("OPENAI_API_BASE", "https://api.openai.com/v1") def analyze_error(self, error_info: Dict, context: Dict) -> Dict[str, Any]: """Use an LLM to analyze an error and generate a solution""" if not self.api_key: return self._fallback_analysis(error_info, context) try: import requests prompt = f"""作为 AI Agent 自进化引擎,请分析以下执行错误并提供解决方案: 错误类型: {error_info.get('error_type', 'Unknown')} 错误信息: {error_info.get('error_message', '')} 任务类型: {error_info.get('task_type', 'general')} 触发输入: {json.dumps(error_info.get('trigger_input', ''), ensure_ascii=False)} 上下文: {json.dumps(context, ensure_ascii=False)} 请提供: 1. 错误原因分析 2. 建议的解决方案 3. 策略优化建议 4. 关键词标签(用于搜索) 以 JSON 格式返回: {{ "analysis": "错误原因分析", "solution": "建议的解决方案", "strategy_delta": "策略优化建议", "keywords": ["关键词1", "关键词2"] }} """ response = requests.post( f"{self.api_base}/chat/completions", headers={ "Authorization": f"Bearer {self.api_key}", "Content-Type": "application/json" }, json={ "model": self.model, "messages": [ {"role": "system", "content": "你是一个专业的 AI Agent 自进化引擎,擅长分析错误并提供优化建议。"}, {"role": "user", "content": prompt} ], "temperature": 0.7 ...[truncated 2931 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Replace unrestricted `OPENAI_API_BASE` handling with an explicit allowlist of approved HTTPS origins. 2. Parse and normalize the endpoint before use, rejecting non-HTTPS URLs, embedded credentials, redirects to unapproved hosts, and unexpected ports. 3. Do not attach an API key unless the normalized destination matches the credential's configured provider. 4. Build a minimal request object from allowlisted fields rather than serializing arbitrary `input` and `context` values. 5. Add secret detection and redaction for API keys, authorization headers, passwords, cookies, private keys, tokens, personal information, and connection strings. 6. Require explicit user consent before transmitting task data and display the destination and fields that will be sent. 7. Provide a local-only analysis mode and make remote analysis opt-in. 8. Disable automatic redirects or validate the final redirect destination before forwarding credentials. 9. Add tests proving that malicious endpoint values and sensitive context fields are rejected or redacted. ]]>
