T09 · Insecure Skill Coding Practices
Warning
- Location
- scripts/trendproof.py:59
- Finding
- API Credentials Can Be Forwarded to an Arbitrary Environment-Controlled Endpoint<![CDATA[ ## Vulnerability Details **File Location**: `scripts/trendproof.py`, lines 59–79 **Vulnerability Type**: Unrestricted destination for authenticated network requests **Risk Level**: Medium ### Vulnerable Code ```python def _get_base_url() -> str: return os.environ.get("TRENDPROOF_BASE_URL", DEFAULT_BASE_URL).rstrip("/") # ── HTTP ──────────────────────────────────────────────────────────────────── def _post(endpoint: str, body: dict, api_key: str | None) -> dict: base = _get_base_url() url = f"{base}{endpoint}" data = json.dumps(body).encode() headers = {"Content-Type": "application/json", "Accept": "application/json"} if api_key: headers["Authorization"] = f"Bearer {api_key}" req = urllib.request.Request(url, data=data, headers=headers, method="POST") try: with urllib.request.urlopen(req, timeout=30) as resp: return json.loads(resp.read()) ``` ### Technical Analysis The request destination is obtained from the `TRENDPROOF_BASE_URL` environment variable without validating its scheme, hostname, port, or origin. The `_post` function subsequently adds the user's TrendProof API key to the `Authorization` header for requests sent to that destination. Consequently, an environment override can cause the script to disclose both the API credential and submitted keyword data to a server other than the documented `https://trendproof.dev` service. Because the base URL can include an arbitrary scheme and host accepted by `urllib`, the code does not preserve the intended trust boundary around the credential. An endpoint override may be useful during development, but unrestricted overrides are not required for the Skill's declared production functionality. Production credentials should not be attached to requests sent to untrusted origins. ### Attack Path 1. An attacker influences the environment used to launch the Skill, such as through a compromised wrapper, automation configuration, shell profil ...[truncated 1129 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Pin production requests to the documented origin: ```python DEFAULT_BASE_URL = "https://trendproof.dev" ``` 2. Remove `TRENDPROOF_BASE_URL` support in production, or validate the parsed URL before constructing a request: - Require the `https` scheme. - Require the exact allowlisted hostname `trendproof.dev`. - Reject embedded credentials, fragments, unexpected ports, and ambiguous hostnames. - Normalize and compare the parsed origin rather than relying on string prefixes. 3. If endpoint overrides are necessary for testing: - Require an explicit development-only flag. - Refuse to send a production API key to a non-allowlisted origin. - Use separate test credentials. - Display a clear warning before making the request. 4. Consider constructing URLs from a fixed trusted origin and allowlisting endpoint paths such as `/api/analyze` and `/api/related`. 5. Add automated tests confirming that malformed URLs, HTTP URLs, subdomain lookalikes, and arbitrary external hosts are rejected. ]]>
