T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/_shopee_shop_flash_sale_common.py:18
- Finding
- Environment-Controlled Endpoints Can Exfiltrate Authentication Credentials<![CDATA[ ## Vulnerability Details **File Location**: `scripts/_shopee_shop_flash_sale_common.py:18-24, 64-91`; `scripts/onboarding.py:68-89, 190-197, 225-246, 399-453` **Vulnerability Type**: Credential disclosure through unrestricted endpoint configuration **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" ).rstrip("/") STORE_TOKENS_ENDPOINT = f"{API_BASE_URL}/shopee/storeTokens" DEVELOPER_PROXY_ENDPOINT = f"{API_BASE_URL}/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", }, method="POST", ) try: with urlopen(req, timeout=150) as response: return json.loads(response.read().decode("utf-8")) ``` The onboarding implementation similarly accepts unrestricted endpoint overrides: ```python def _login_base() -> str: return _env_base("LINKFOX_LOGIN_API_URL", "https://api.linkfox.com") def _agent_user_base() -> str: return _env_base("LINKFOX_AGENT_USER_API_URL", "https://agent-api.linkfox.com") ``` It then sends authentication data to those destinations: ```python def _headers(source: str, origin_host: str, *, access_token: str = "", user_id: str = "", group_id: str = "") -> dict: h = { "Accept": "application/json, text/plain, */*", "Content-Type": "application/json;charset=UTF-8", "Origin": f"https://{origin_host}", "Referer": f"https://{origin_host}/", "source": source, "User-Agent": UA, } if access_token: h["authorization"] = access_token h["uid"] = _uid_header(a ...[truncated 2521 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Allowlist the exact production hosts that may receive credentials, including: - `tool-gateway.linkfox.com` - `api.linkfox.com` - `agent-api.linkfox.com` 2. Parse configured URLs with a standard URL parser and require: - The `https` scheme - An exact approved hostname - No embedded username or password - No unexpected query string or fragment - An approved port, normally 443 3. Prevent cross-origin redirects when authorization headers or tokens are present. 4. Reject IP literals and hostname suffix tricks such as `tool-gateway.linkfox.com.attacker.example`. 5. If custom endpoints are needed for development, require an explicit development-mode switch and prohibit production credentials in that mode. 6. Keep endpoint overrides disabled by default and document their security implications. 7. Add automated tests proving that HTTP URLs, unapproved domains, malformed URLs, and redirect-based credential forwarding are rejected. ]]>
