T09 · Insecure Skill Coding Practices
- Location
scripts/ask_free_ai.py:45- Finding
Automatic Cloud Fallback May Disclose Sensitive Prompt Content
- Content
View full analysis
Optional[str]: """调用 Cloudflare Workers AI""" try: import requests account_id = os.getenv("CF_ACCOUNT_ID") api_token = os.getenv("CF_API_TOKEN") if not account_id or not api_token: print("[Cloudflare] 未配置", file=sys.stderr) return None url = f"https://api.cloudflare.com/client/v4/accounts/{account_id}/ai/run/@cf/meta/llama-3.1-8b-instruct" headers = {"Authorization": f"Bearer {api_token}"} data = {"prompt": prompt} resp = requests.post(url, json=data, headers=headers, timeout=60) if resp.status_code == 200: return resp.json().get("result", {}).get("response", "").strip() except Exception as e: print(f"[Cloudflare] 失败: {e}", file=sys.stderr) return None def call_groq(prompt: str) -> Optional[str]: """调用 Groq 免费 API""" try: import requests api_key = os.getenv("GROQ_API_KEY") if not api_key: print("[Groq] 未配置", file=sys.stderr) return None url = "https://api.groq.com/openai/v1/chat/completions" headers = {"Authorization": f"Bearer {api_key}", "Content-Type": "application/json"} data = { "model": "llama-3.1-8b-instant", "messages": [{"role": "user", "content": prompt}], "max_tokens": 512 } resp = requests.post(url, json=data, headers=headers, timeout=60) if resp.status_code == 200: return resp.json().get("choices", [{}])[0].get("message", {}).get("content", "").strip() except Exception as e: print(f"[Groq] 失败: {e}", file=sys.stderr) return None def ...[truncated 3729 chars]- Remediation
View remediation
