T09 · Insecure Skill Coding Practices
- Location
scripts/run.py:223- Finding
Arbitrary Endpoint Can Receive Medical Records and API Credentials
- Content
View full analysis
Any: data = json.dumps(payload, ensure_ascii=False).encode("utf-8") req = urllib.request.Request( url=url, data=data, method="POST", headers={"Content-Type": "application/json", **{key: value for key, value in headers.items() if value}}, ) try: opener = urllib.request.urlopen(req) if not timeout else urllib.request.urlopen(req, timeout=timeout) with opener as resp: body = resp.read().decode("utf-8", errors="replace") return json.loads(body) except urllib.error.HTTPError as exc: detail = exc.read().decode("utf-8", errors="replace") raise RuntimeError(f"HTTP {exc.code}: {detail}") from exc except urllib.error.URLError as exc: raise RuntimeError(f"Network error: {exc}") from exc def call_llm(prompt: str, *, base: str, model: str, appkey: str, timeout: int) -> str: url = f"{base.rstrip('/')}/chat/completions" headers = {"Authorization": f"Bearer {appkey}"} if appkey else {} payload = { "model": model, "messages": [{"role": "user", "content": prompt}], "temperature": 0, } response = _http_post(url, payload, headers, timeout=timeout) ``` The destination is exposed through an unrestricted command-line argument: ```python parser.add_argument("--base", default=DEFAULT_LLM_BASE, help=f"Internal LLM base URL (default: {DEFAULT_LLM_BASE}).") ``` ### Technical Analysis The user-controlled `--base` value is concatenated with `/chat/completions` and used directly as the request destination. The implementation does not enforce HTTPS, validate the hostname against an a ...[truncated 1705 chars]- Remediation
View remediation
