T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/robot_cmd.py:35
- Finding
- Credentials Can Be Redirected to an Untrusted or Cleartext API Endpoint<![CDATA[ ## Vulnerability Details **File Location**: `scripts/robot_cmd.py:35-54` and `scripts/robot_cmd.py:531-532` **Vulnerability Type**: Unrestricted destination for authenticated network requests **Risk Level**: High ### Complete Code Snippet ```python def get_config() -> dict: return { "base_url": _env("JOYIN_API_BASE", "https://api-open-test.joyin-ai.com").rstrip("/"), "auth_key": _env("JOYIN_AUTH_KEY"), "device_sn": _env("JOYIN_DEVICE_SN"), "device_type_id": _env("JOYIN_DEVICE_TYPE_ID", "3"), } def _headers(cfg: dict) -> dict: return { "Content-Type": "application/json", "Authorization": cfg["auth_key"], "Device-Sn": cfg["device_sn"], "Device-Type-Id": str(cfg["device_type_id"]), } ``` The command-line override is applied without validation: ```python if args.base_url: cfg["base_url"] = args.base_url.rstrip("/") ``` ### Technical Analysis The API destination can be supplied through `JOYIN_API_BASE` or the global `--base-url` option. The implementation does not require HTTPS, validate the hostname, reject embedded credentials, or restrict the destination to an approved JoyIn domain. All API requests use `_headers()`, which attaches the JoyIn authorization key, device serial number, and device type identifier. Consequently, any command can disclose these values to the configured host. If an attacker can influence the environment or command arguments, authenticated requests can be redirected to an attacker-controlled server. A cleartext `http://` endpoint would also expose credentials and request contents to network observers. This behavior exceeds the minimum privilege necessary for robot control because the official functionality only requires communication with a trusted JoyIn API endpoint. There is no evidence that the default JoyIn URL is malicious, but the missing destination and transport controls create an exploitable credential-disclosure path. ### Attac ...[truncated 1108 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Require `https://` for every API base URL and reject cleartext HTTP. 2. Parse the URL with `urllib.parse.urlparse()` and reject user-info, fragments, malformed ports, and unexpected schemes. 3. Allowlist official JoyIn API hostnames by default. 4. If custom endpoints are necessary, require an explicit opt-in configuration and display the destination before transmitting credentials. 5. Prevent authenticated cross-host redirects, or verify the redirect destination before forwarding the `Authorization` and device headers. 6. Consider certificate pinning where operationally feasible. 7. Keep separate credentials for development and production endpoints, with the narrowest available device-level permissions. ]]>
