T09 · Insecure Skill Coding Practices
- Location
scripts/report.py:8- Finding
API Credential and User Report Content Transmitted over Plaintext HTTP
- Content
View full analysis
Vulnerability Details
File Location:
scripts/report.py, lines 8-29 and 43-55
Vulnerability Type: Plaintext transmission of sensitive information
Risk Level: HighVulnerable Code
python API_BASE_URL = "http://intra-znjs-yqt-agent-wx-beta.midu.cc".rstrip("/") def _resolve_api_key(base_url: str) -> str: """Prefer MIDU_API_KEY; otherwise GET {base}/apiKey.""" key = os.environ.get("MIDU_API_KEY") if key and key.strip(): return key.strip() url = f"{base_url}/apiKey" response = requests.get(url, timeout=60) response.raise_for_status() text = response.text.strip() if not text: return "" try: data = json.loads(text) if isinstance(data, dict): for k in ("key", "api_key", "token", "data"): v = data.get(k) if isinstance(v, str) and v.strip(): return v.strip() except json.JSONDecodeError: pass return textpython def generate_report(message: str) -> dict: """Generate a public opinion analysis report. Args: query: The query to generate a public opinion analysis report. Returns: A dictionary containing the public opinion analysis report. The result is in Markdown format. """ root = API_BASE_URL api_key = _resolve_api_key(root) chat_url = f"{root}/api/chat" headers = {"Content-Type": "application/json", "podName": "public-opinion-report-skill-user", "podNameSpace": "beta-nlp"} if api_key: headers["Authorization"] = "Bearer %s" % api_key body = {"messages": [{"role": "user", "content": message}]} response = requests.post(chat_url, json=body, headers=headers, timeout=1200) response.raise_for_status() data = response.json()Technical Analysis
The service base URL is explicitly configured with the unencrypted
http://s ...[truncated 2674 chars]- Remediation
View remediation
Remediation Suggestions
- Replace the service URL with an authenticated HTTPS endpoint:
python API_BASE_URL = "https://intra-znjs-yqt-agent-wx-beta.midu.cc".rstrip("/") - Ensure the service presents a certificate issued for the expected hostname. Retain certificate verification and never set
verify=False. - Reject any configured base URL whose scheme is not HTTPS, preferably using
urllib.parse.urlparse. - Restrict or disable redirects. If redirects are required, verify that every destination retains HTTPS and belongs to an explicit hostname allowlist.
- Remove the automatic
/apiKeyfallback. RequireMIDU_API_KEYthrough secure configuration and fail closed when it is absent:python api_key = os.environ.get("MIDU_API_KEY", "").strip() if not api_key: raise RuntimeError("MIDU_API_KEY is required") - Store the API key in an approved secret-management facility. If a local configuration file must be used, enforce restrictive permissions and prevent it from being committed or logged.
- Scope the API credential to only the report-generation operation, apply expiration and rotation, and revoke any credential previously transmitted over HTTP.
- Avoid including credentials, full response bodies, or sensitive report prompts in errors and operational logs.
- Add automated tests that fail if the configured endpoint uses HTTP or if a redirect attempts to downgrade an HTTPS request.
- Replace the service URL with an authenticated HTTPS endpoint:
