T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/taker_api.py:15
- Finding
- API Key Can Be Transmitted to an Arbitrary User-Controlled Server<![CDATA[ ## Vulnerability Details **File Location**: `scripts/taker_api.py:15-44` **Vulnerability Type**: Unrestricted credential destination **Risk Level**: High ### Vulnerable Code ```python def build_env_config(env: str, base_url: Optional[str], api_key: str) -> EnvConfig: """Resolve final base URL from env / override.""" if not api_key: raise SystemExit("api_key is required for Taker API calls.") if base_url: return EnvConfig(base_url=base_url.rstrip("/"), api_key=api_key) if env == "test": return EnvConfig(base_url="https://api-qa.proto.stove.finance", api_key=api_key) # default: production return EnvConfig(base_url="https://proto.stove.finance", api_key=api_key) def _build_request( url: str, method: str, cfg: EnvConfig, body: Optional[Dict[str, Any]] = None, ) -> request.Request: if body is not None: data = json.dumps(body).encode("utf-8") else: data = None req = request.Request(url, method=method, data=data) req.add_header("Content-Type", "application/json") req.add_header("X-API-Key", cfg.api_key) return req ``` The unrestricted override is also exposed as a command-line option at `scripts/taker_api.py:176-179`: ```python parser.add_argument( "--base-url", help="可选:自定义 API 根地址,设置后优先生效。", ) ``` ### Technical Analysis The `--base-url` option accepts an arbitrary URL without validating its scheme, hostname, port, or destination. Every request created for the selected URL receives the sensitive `X-API-Key` header. Sending an API key over the network is necessary for the Skill's declared API functionality when the destination is a trusted Stove Protocol service. Allowing the same credential to be sent to an arbitrary destination exceeds that minimum requirement. No controls limit requests to the two documented endpoints: - `https://proto.stove.finance` - `https://api-qa.proto.stove.finance` The implementation also does not explicitl ...[truncated 1733 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Remove `--base-url` unless custom endpoints are essential to the supported functionality. 2. If overrides are required, enforce an explicit hostname allowlist containing only approved Stove Protocol environments. 3. Parse the URL with `urllib.parse.urlsplit` and require: - The `https` scheme. - An exact approved hostname. - No embedded username or password. - An approved port, normally 443. 4. Reject loopback, private, link-local, multicast, and otherwise non-public resolved addresses where custom hosts are supported. 5. Disable redirects or validate every redirect destination before forwarding authentication headers. 6. Do not attach `X-API-Key` until the final request destination has passed validation. 7. Separate production and test credentials and restrict each credential server-side to the minimum necessary API operations. 8. Add tests proving that HTTP URLs, deceptive subdomains, user-information URLs, internal IP addresses, and redirects to untrusted hosts are rejected. ]]>
