T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/client.py:32
- Finding
- Unvalidated API Endpoint Override Exposes Credential Material and Workload Data<![CDATA[ ## Vulnerability Details **File Location**: `scripts/client.py:32-34` and `scripts/client.py:163-202` **Vulnerability Type**: Unvalidated credential-bearing network destination **Risk Level**: High ### Vulnerable Code ```python _DEFAULT_HOST = "oceanus.tencentcloudapi.com" HOST = os.environ.get("OCEANUS_ENDPOINT", _DEFAULT_HOST) ENDPOINT = f"https://{HOST}" ``` ```python secret_id, secret_key = get_credentials() timestamp = int(time.time()) date = datetime.fromtimestamp(timestamp, tz=timezone.utc).strftime("%Y-%m-%d") payload = json.dumps(params) authorization = _build_authorization( secret_id, secret_key, service, date, str(timestamp), payload ) connect_timeout = int(os.environ.get("OCEANUS_API_CONNECT_TIMEOUT", "10")) read_timeout = int(os.environ.get("OCEANUS_API_READ_TIMEOUT", "60")) headers = { "Authorization": authorization, "Content-Type": "application/json; charset=utf-8", "Host": HOST, "X-TC-Action": action, "X-TC-Timestamp": str(timestamp), "X-TC-Version": version, "X-TC-Region": region, "User-Agent": DEFAULT_USER_AGENT, } token = os.environ.get("TENCENTCLOUD_SECURITY_TOKEN", "") if token: headers["X-TC-Token"] = token try: req = Request( ENDPOINT, data=payload.encode("utf-8"), headers=headers, method="POST", ) resp = urlopen(req, timeout=max(connect_timeout, read_timeout)) ``` ### Technical Analysis The API host is taken directly from the `OCEANUS_ENDPOINT` environment variable without validating that it is an approved TencentCloud endpoint. All Oceanus API calls are subsequently sent to this destination. Each request includes: - The TencentCloud SecretId inside the `Authorization` header. - A request signature derived from the SecretKey. - The complete STS security token when temporary credentials are used. - The complete serialized API payload. - Operation, region, version, and timestamp metadata. The long-term SecretKey is not transmitted d ...[truncated 1803 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Remove `OCEANUS_ENDPOINT` overrides from production execution unless they are operationally required. 2. If endpoint overrides are necessary for testing, require an explicit development-mode option and reject them by default. 3. Parse the destination with `urllib.parse.urlsplit` and enforce: - HTTPS only. - No URL user information. - No path, query string, or fragment in a host override. - No unexpected port. - No IP literal. - An exact approved TencentCloud hostname or a narrowly defined allowlist. 4. Do not rely on a broad suffix check alone. Normalize the hostname and protect against suffix-confusion values such as `tencentcloudapi.com.attacker.example`. 5. Disable automatic redirects for credential-bearing requests, or validate every redirect destination before forwarding sensitive headers. 6. Never forward `Authorization` or `X-TC-Token` across an origin change. 7. Add unit tests covering malicious hosts, user-information syntax, ports, IP literals, malformed values, and redirect attempts. 8. Document any supported private endpoint explicitly and bind it to a trusted configuration source rather than an ambient environment variable. ]]>
