T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/_shop_analytics_common.py:15
- Finding
- Configurable Gateway Allows Sensitive Credentials to Be Sent to an Untrusted Destination<![CDATA[ ## Vulnerability Details **File Location**: `scripts/_shop_analytics_common.py`, lines 15-19 and 60-84 **Vulnerability Type**: `T09: Insecure Skill Coding Practices` **Risk Level**: High ### Vulnerable Code ```python API_BASE_URL = ( os.environ.get("LINKFOX_TOOL_GATEWAY") or os.environ.get("TIKTOK_SHOP_API_BASE_URL") or "https://tool-gateway.linkfox.com" ).rstrip("/") DEVELOPER_PROXY_ENDPOINT = f"{API_BASE_URL}/tiktokShop/developerProxy" ``` ```python def get_api_key() -> str: key = os.environ.get("LINKFOX_AGENT_API_KEY") or os.environ.get("LINKFOXAGENT_API_KEY") if not key: print("API Key 未配置", file=sys.stderr) sys.exit(1) return key 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", ""), "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 The network request is necessary for the Skill's declared functionality, but its destination is not restricted to the documented LinkFox gateway. The `LINKFOX_TOOL_GATEWAY` and `TIKTOK_SHOP_API_BASE_URL` environment variables can replace the entire gateway origin with an arbitrary URL. The code does not enforce HTTPS, validate the destination hostname, restrict ports, reject URL user information, or otherwise verify that the destination belongs to LinkFox. Every request to the configured endpoint includes: - The LinkFox agent API key in the `Authorization` header. - The merchant's `openId` in ...[truncated 1701 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Pin the production gateway to an immutable HTTPS origin where operationally possible. 2. If configurability is required for testing, parse the URL and enforce an explicit allowlist of trusted hostnames. 3. Reject non-HTTPS schemes, URL user information, fragments, unexpected ports, IP-literal destinations, and malformed URLs. 4. Separate test and production configuration so production credentials cannot be sent to test endpoints. 5. Confirm redirect behavior and disable or strictly validate redirects so a trusted endpoint cannot redirect credentials to another origin. 6. Remove `SESSION_ID`, `MODE_ID`, and `APP_NAME` unless the gateway strictly requires them. If required, document their purpose and minimize their contents. 7. Use a narrowly scoped, short-lived API credential restricted to the required developer-proxy operation. 8. Add automated tests proving that untrusted hosts and plain HTTP destinations are rejected before any request is issued. ]]>
