T09 · Insecure Skill Coding Practices
- Location
llm_service_manager.py:73- Finding
API Credentials and Prompts May Be Transmitted to an Arbitrary Plaintext Endpoint
- Content
View full analysis
Vulnerability Details
File Location:
llm_service_manager.py, lines 73-86 and 205-212
Vulnerability Type: Unvalidated API endpoint and plaintext transmission of sensitive data
Risk Level: MediumVulnerable Code
python def _query_api(url: str, model: str, prompt: str, api_key: str = "") -> str: """向OpenAI兼容API发送查询""" try: import urllib.request headers = {"Content-Type": "application/json"} if api_key: headers["Authorization"] = f"Bearer {api_key}" body = json.dumps({ "model": model, "messages": [{"role": "user", "content": prompt}], "max_tokens": 512, "temperature": 0.3 }).encode() req = urllib.request.Request(f"{url}/chat/completions", data=body, headers=headers) with urllib.request.urlopen(req, timeout=30) as r: data = json.loads(r.read()) return data["choices"][0]["message"]["content"]python if cmd.startswith("api:"): prompt = cmd[4:].strip() openai_url = os.environ.get("OPENAI_BASE_URL", "http://localhost:8000/v1") api_key = os.environ.get("OPENAI_API_KEY", "") model = os.environ.get("OPENAI_MODEL", "gpt-4o-mini") if not prompt: return "请输入查询内容" return _query_api(openai_url, model, prompt, api_key)Technical Analysis
The value of
OPENAI_BASE_URLis used as the request destination without validating its scheme, hostname, or trust level._query_apithen attachesOPENAI_API_KEYas a bearer credential and includes the complete user prompt in the request body.Sending prompts and credentials to a configured OpenAI-compatible service is required by the declared API-query functionality. However, allowing a non-loopback endpoint to use plain HTTP is not necessary and violates secure transport expectations. On plain HTTP, an attacker with network visibility or an active man-in-the-middle position c ...[truncated 1676 chars]
- Remediation
View remediation
Remediation Suggestions
- Parse
OPENAI_BASE_URLwithurllib.parse.urlparseand reject unsupported schemes. - Require HTTPS for every non-loopback destination.
- Permit HTTP only when the parsed hostname is a validated loopback address such as
127.0.0.1,::1, orlocalhost; do not rely on substring matching. - Reject URLs containing embedded user information, unexpected fragments, or malformed hostnames.
- Maintain an explicit allowlist of trusted API origins where practical.
- Require user confirmation before sending credentials or prompts to a newly configured remote origin.
- Avoid attaching
OPENAI_API_KEYto endpoints that are not explicitly trusted. - Document that API-mode prompts leave the local system and may contain sensitive information.
- Use short-lived, narrowly scoped API credentials and provide rotation guidance in case of endpoint misconfiguration.
- Add tests confirming that remote
http://endpoints, malformed URLs, and untrusted destinations are rejected while loopback development endpoints remain supported.
- Parse
