T09 · Insecure Skill Coding Practices
Error
- Location
- src/payment_api_client.py:52
- Finding
- Payment API credentials may be transmitted over plaintext HTTP<![CDATA[ ## Vulnerability Details **File Location**: `src/config_loader.py:86-104`, `src/payment_api_client.py:52-74` **Vulnerability Type**: Unvalidated transport security for sensitive API requests **Risk Level**: High ### Vulnerable Code ```python # src/config_loader.py:86-104 config = { "api_key": os.getenv("PAYMENT_API_KEY"), "api_secret": os.getenv("PAYMENT_API_SECRET"), "api_url": os.getenv("PAYMENT_API_URL"), "timeout": int(os.getenv("PAYMENT_API_TIMEOUT", "30")) if os.getenv("PAYMENT_API_TIMEOUT") else 30, } env_config = ConfigLoader.load_env_file(env_name) if not config["api_key"]: config["api_key"] = env_config.get("PAYMENT_API_KEY") if not config["api_secret"]: config["api_secret"] = env_config.get("PAYMENT_API_SECRET") if not config["api_url"]: config["api_url"] = env_config.get("PAYMENT_API_URL") if not config["api_url"]: config["api_url"] = "https://api.zlclaw.com" ``` ```python # src/payment_api_client.py:52-74 url = f"{self.api_url}/{endpoint}" signature = self._generate_signature(method, endpoint, data) timestamp = str(int(time.time())) headers = { "Authorization": f"Bearer {self.api_key}", "X-Signature": signature, "X-Timestamp": timestamp, "Content-Type": "application/json" } try: async with self.session.request( method, url, json=data, headers=headers, timeout=aiohttp.ClientTimeout(total=self.timeout) ) as response: ``` ### Technical Analysis The application accepts `PAYMENT_API_URL` from the process environment or a configuration file without validating its scheme. Although the default endpoint uses HTTPS, a configured value beginning with `http://` is accepted and used directly. Every request includes the payment API key in an `Authorization` header. Payment creation and refund requests also carry transaction data in the request body. HMAC signing provides integrity only to parties that cannot recover or replace the request context; it does ...[truncated 1211 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Parse `PAYMENT_API_URL` using `urllib.parse.urlparse`. 2. Reject every scheme except `https`. 3. Reject URLs containing embedded user information, fragments, malformed ports, or unexpected path components. 4. Maintain an allowlist of approved payment API hostnames where deployment requirements permit it. 5. Keep TLS certificate verification enabled and do not expose a configuration option that silently disables it. 6. Consider certificate or public-key pinning for tightly controlled payment infrastructure. 7. Add automated tests confirming that `http://`, malformed, and unapproved endpoints are rejected before any credentials are transmitted. 8. Use narrowly scoped and rotatable payment API credentials to reduce the impact of accidental disclosure. ]]>
