T09 · Insecure Skill Coding Practices
- Location
dialectic_runner.py:100- Finding
Search Enabled by Default Discloses Potentially Sensitive Business Information
- Content
View full analysis
List[Dict]: """执行内置搜索(不依赖外部Skill)""" import urllib.parse import urllib.request # 1. 尝试 Tavily API api_key = os.environ.get("TAVILY_API_KEY") if api_key: try: import requests url = "https://api.tavily.com/search" payload = {"query": query, "api_key": api_key, "max_results": count} resp = requests.post(url, json=payload, timeout=15) if resp.status_code == 200: data = resp.json() results = [] for item in data.get("results", [])[:count]: results.append({ "title": item.get("title", ""), "url": item.get("url", ""), "description": item.get("content", "") }) if results: return results except Exception as e: print(f"[知识增强] Tavily API失败: {e}", file=sys.stderr) # 2. Fallback: Brave Search API api_key = os.environ.get("BRAVE_API_KEY") if api_key: try: import requests url = "https://api.search.brave.com/res/v1/web/search" headers = {"X-Subscription-Token": api_key, "Accept": "application/json"} params = {"q": query, "count": min(count, 10)} resp = requests.get(url, headers=headers, params=params, timeout=15) if resp.status_code == 200: data = resp.json() results = [] for item in data.get("web", {}).get("results", [])[:count]: results.append( ...[truncated 4177 chars]- Remediation
View remediation
Dict[str, Any]: ``` 2. Replace the ambiguous CLI option with an explicit opt-in flag: ```python parser.add_argument( "--enable-search", action="store_true", default=False, help="Send search queries to an external knowledge provider" ) ``` 3. If both enable and disable flags are required, use a mutually exclusive group with a secure default: ```python group = parser.add_mutually_exclusive_group() group.add_argument("--enable-search", dest="enable_search", action="store_true") group.add_argument("--disable-search", dest="enable_search", action="store_false") parser.set_defaults(enable_search=False) ``` 4. Before the first request, clearly identify: - The destination provider. - The data fields that will be transmitted. - Whether constraints and budget figures will be included. - The provider's applicable privacy or retention policy. 5. Require separate consent before incorporating constraints into search queries. By default, search only a sanitized, minimally necessary topic. 6. Add tests confirming that: - No network request occurs without `--enable-search`. - `--disable-search` prevents every provider fallback. - Sensitive constraints are not transmitted unless separately authorized. 7. Update `SKILL.md` so the documented behavior exactly matches the implementation. ]]>
