T09 · Insecure Skill Coding Practices
- Location
scripts/check_credential.py:23- Finding
Credential Validation Transmits API Keys Without Enforcing HTTPS
- Content
View full analysis
Vulnerability Details
File Location:
scripts/check_credential.py:23-32
Vulnerability Type: API credential exposure over an unencrypted connection
Risk Level: HighVulnerable Code
python base_url = _require_env("UNIPROFIT_API_BASE_URL").rstrip("/") api_key = _require_env(KEY_ENV) req = urllib.request.Request( f"{base_url}/openclaw/credential/me", headers={"X-UniProfit-Key": api_key}, method="GET", ) try: with urllib.request.urlopen(req, timeout=20) as resp:Technical Analysis
The script accepts
UNIPROFIT_API_BASE_URLas an arbitrary string and does not parse its scheme or require HTTPS before placingUNIPROFIT_TRADE_SEARCH_KEYin theX-UniProfit-Keyrequest header.If the configured URL uses
http://, the credential is transmitted in plaintext. A network-positioned attacker could inspect the request and recover the API key. Documentation provides an HTTPS example, but an example does not provide runtime enforcement.Attack Path
- A deployment, user, or configuration-management error sets
UNIPROFIT_API_BASE_URLto anhttp://endpoint. - The credential-check script is executed.
- The script places the UniProfit API key in the
X-UniProfit-Keyheader. urllib.request.urlopensends the request over an unencrypted connection.- An attacker able to observe network traffic captures the header value.
- The attacker reuses the stolen credential against the UniProfit API.
Impact Assessment
Exploitation does not grant local operating-system privileges, but it can compromise the authority represented by the API key. An attacker may validate or reuse the credential, access trade-search functionality available to that key, consume paid quota, and impersonate the authorized caller within the key's API scope.
- A deployment, user, or configuration-management error sets
- Remediation
View remediation
Remediation Suggestions
- Parse the configured URL using
urllib.parse.urlparse. - Reject every scheme other than
https. - Reject malformed URLs and URLs containing embedded user information.
- Consider allowlisting the official UniProfit API hostname to reduce credential exfiltration through configuration manipulation.
- If local development requires cleartext HTTP, permit it only through an explicit development-only option and only for loopback addresses such as
127.0.0.1orlocalhost. - Document HTTPS as mandatory rather than providing it only as an example.
- Add automated tests confirming that
http://and malformed base URLs are rejected before any request is made.
Example hardening:
python from urllib.parse import urlparse def _require_https_base_url(value: str) -> str: value = value.rstrip("/") parsed = urlparse(value) if parsed.scheme != "https" or not parsed.hostname: raise SystemExit("UNIPROFIT_API_BASE_URL must be a valid HTTPS URL") if parsed.username or parsed.password: raise SystemExit("Embedded URL credentials are not allowed") return value base_url = _require_https_base_url( _require_env("UNIPROFIT_API_BASE_URL") )- Parse the configured URL using
