T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/chuhaijiang_creator_search.py:29
- Finding
- Redirectable API Endpoints Can Exfiltrate Authentication Credentials<![CDATA[ ## Vulnerability Details **File Location**: `scripts/chuhaijiang_creator_search.py:29-31, 139-174`; identical behavior exists in the other seven `scripts/chuhaijiang_creator_*.py` files. Related endpoint overrides occur in `scripts/onboarding.py:69-85, 189-221, 399-459`. **Vulnerability Type**: Unrestricted credential transmission to environment-controlled endpoints **Risk Level**: High ### Vulnerable Code ```python def get_api_base() -> str: """Gateway base address: environment override, then production default.""" return (os.environ.get("LINKFOX_TOOL_GATEWAY") or "https://tool-gateway.linkfox.com").rstrip("/") def get_api_key(): key = (os.environ.get("LINKFOX_AGENT_API_KEY") or os.environ.get("LINKFOXAGENT_API_KEY")) if not key: sys.exit(1) return key def call_api(params): global _LAST_CALL_WAS_HTTP_ERROR _LAST_CALL_WAS_HTTP_ERROR = False api_url = get_api_url() api_key = get_api_key() data = json.dumps(params).encode("utf-8") headers = { "Authorization": api_key, "Content-Type": "application/json", "User-Agent": "LinkFox-Skill/2.0", "SESSION_ID": (os.environ.get("SESSION_ID") or "").strip(), "MESSAGE_ID": os.environ.get("MESSAGE_ID", ""), "MODE_ID": os.environ.get("MODE_ID", ""), "APP_NAME": os.environ.get("APP_NAME", ""), } req = Request(api_url, data=data, headers=headers, method="POST") try: with urlopen(req, timeout=150) as response: raw = response.read().decode("utf-8") try: return json.loads(raw) except json.JSONDecodeError: return {"error": "Invalid JSON response", "details": raw[:500]} except HTTPError as e: _LAST_CALL_WAS_HTTP_ERROR = True body = e.read().decode("utf-8", errors="replace") if e.fp else "" try: return json.loads(body) if body else { "error": f"HTTP { ...[truncated 2929 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Remove production endpoint overrides unless they are essential for a documented development mode. 2. Require `https` for every configured endpoint and reject all other schemes. 3. Parse endpoints with `urllib.parse.urlsplit` and enforce an explicit allowlist such as: - `tool-gateway.linkfox.com` - `api.linkfox.com` - `agent-api.linkfox.com` 4. Reject URLs containing user information, fragments, unexpected ports, malformed hosts, or IP-literal destinations. 5. Disable automatic redirects or validate every redirect destination against the same allowlist before forwarding credentials. 6. Separate development credentials from production credentials. Never send production bearer tokens to a development override. 7. Add tests proving that HTTP URLs, lookalike domains, subdomain confusion, user-information tricks, and redirects to untrusted hosts are rejected. ]]>
