T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/_shopee_account_health_common.py:18
- Finding
- Credential Exfiltration Through an Environment-Controlled Gateway<![CDATA[ ## Vulnerability Details **File Location**: `scripts/_shopee_account_health_common.py:18-20, 70-88` **Vulnerability Type**: Unrestricted credential-bearing network destination **Risk Level**: High ### Vulnerable Code ```python API_BASE_URL = os.environ.get("LINKFOX_TOOL_GATEWAY") or os.environ.get("SHOPEE_API_BASE_URL") or "https://tool-gateway.linkfox.com" STORE_TOKENS_ENDPOINT = f"{API_BASE_URL.rstrip('/')}/shopee/storeTokens" DEVELOPER_PROXY_ENDPOINT = f"{API_BASE_URL.rstrip('/')}/shopee/developerProxy" ``` ```python def call_api(endpoint: str, params: dict) -> dict: api_key = get_api_key() data = json.dumps(params).encode("utf-8") req = Request( endpoint, data=data, headers={ "Authorization": api_key, "Content-Type": "application/json", "User-Agent": "LinkFox-Skill/1.0", "SESSION_ID": os.environ.get("SESSION_ID", ""), "MESSAGE_ID": os.environ.get("MESSAGE_ID", ""), "MODE_ID": os.environ.get("MODE_ID", ""), "APP_NAME": os.environ.get("APP_NAME", ""), }, method="POST", ) try: with urlopen(req, timeout=150) as response: return json.loads(response.read().decode("utf-8")) ``` ### Technical Analysis Every Account Health request places the LinkFox API key in the `Authorization` header. The destination is derived from `LINKFOX_TOOL_GATEWAY` or `SHOPEE_API_BASE_URL`, both of which can completely replace the trusted default host. No validation requires HTTPS, checks the destination against an approved hostname, or asks the user to confirm that credentials will be disclosed to a non-default service. Consequently, an environment modification can redirect the API key, session metadata, shop or merchant identifier, and API request parameters to an arbitrary endpoint. The Account Health functionality legitimately requires network access and authentication, but allowing unrestricted redirection o ...[truncated 1291 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Allowlist the exact approved gateway hostname, such as `tool-gateway.linkfox.com`. 2. Require an `https` scheme and reject HTTP, embedded credentials, unexpected ports, fragments, and non-approved hosts. 3. If custom gateways are a necessary enterprise feature, require an explicit command-line option and informed confirmation before sending credentials. 4. Use separate, narrowly scoped credentials for custom endpoints rather than forwarding the primary LinkFox API key. 5. Do not transmit `SESSION_ID`, `MESSAGE_ID`, `MODE_ID`, or `APP_NAME` unless each field is necessary for the requested API operation. 6. Add automated tests confirming that malicious, malformed, HTTP, and look-alike destinations are rejected. 7. Document the exact recipient, data fields, and credential scope before the first network request. ]]>
