T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/__main__.py:23
- Finding
- Unrestricted API Endpoint Allows Credential and Prompt Exfiltration## Vulnerability Details **File Location**: `scripts/__main__.py:23, 34-38, 70-104, 191-209, 262, 291` **Vulnerability Type**: Unvalidated destination for sensitive authenticated requests **Risk Level**: High The Skill allows its API destination to be controlled through the `ALIYUN_BAILIAN_API_HOST` environment variable, the CLI `--base-url` option, or the public Python `base_url` parameter. It then sends the Aliyun API key and complete user-supplied prompt or translation text to that destination without validating its scheme or hostname. ### Vulnerable Code ```python DEFAULT_BASE_URL = os.environ.get("ALIYUN_BAILIAN_API_HOST", "https://coding.dashscope.aliyuncs.com/apps/anthropic") ``` ```python def _get_credentials(api_key: Optional[str] = None, base_url: str = DEFAULT_BASE_URL): key = api_key or os.environ.get("ALIYUN_BAILIAN_API_KEY") if not key: return None, None return key, base_url ``` The chat path places the credential in two headers and sends all chat and system-message content to the selected host: ```python headers = { "Content-Type": "application/json", "Authorization": f"Bearer {key}", "x-api-key": key, "anthropic-version": "2023-06-01" } # Convert messages to Anthropic format anthropic_messages = [] system_content = None for msg in messages: if msg.get("role") == "system": system_content = msg.get("content", "") else: anthropic_messages.append({ "role": msg.get("role"), "content": msg.get("content", "") }) payload = { "model": model, "messages": anthropic_messages, "temperature": temperature, "max_tokens": max_tokens } if system_content: payload["system"] = system_content if stream: payload["stream"] = True api_url = f"{url}/v1/messages" try: if stream: response = requests.post(api_url, headers=headers, json=payload, ...[truncated 3442 chars]
- Remediation
- ## Remediation Suggestions 1. Parse the destination with a standard URL parser and require the `https` scheme. 2. Restrict destinations to an explicit allowlist of supported Alibaba Cloud hosts, such as the documented DashScope regional domains. 3. Compare normalized hostnames exactly or by a carefully implemented subdomain rule; do not use substring or suffix checks that accept domains such as `dashscope.aliyuncs.com.attacker.example`. 4. Reject embedded credentials, fragments, unexpected ports, malformed URLs, and IP-literal destinations unless explicitly required. 5. Disable redirects for authenticated requests or validate every redirect destination before forwarding authentication headers. 6. Remove unrestricted `--base-url` and public `base_url` overrides from normal operation. If custom endpoints are operationally necessary, require an explicit unsafe-development mode and never attach production credentials automatically. 7. Send only the authentication header required by the official API rather than duplicating the credential in both `Authorization` and `x-api-key`. 8. Document that prompts and translation text leave the local environment and identify the approved external provider destinations. 9. Add tests confirming that HTTP URLs, arbitrary domains, deceptive domain suffixes, embedded user information, unexpected ports, and cross-domain redirects are rejected before request headers are constructed or transmitted.
