T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/_auth.py:13
- Finding
- Credentials, access tokens, and user content can be redirected to an arbitrary endpoint<![CDATA[ ## Vulnerability Details **File Location**: `scripts/_auth.py:13, 83-89`; related use in `scripts/create_task.py:17, 47-54`, `scripts/list_voices.py:18, 34-36`, and `scripts/poll_task.py:18, 33-43` **Vulnerability Type**: Unrestricted security-sensitive endpoint configuration **Risk Level**: High ### Vulnerable Code ```python API_BASE = os.environ.get("CHANJING_API_BASE", "https://open-api.chanjing.cc") ``` ```python url = API_BASE + "/open/v1/access_token" req = urllib.request.Request( url, data=json.dumps({"app_id": app_id, "secret_key": secret_key}).encode("utf-8"), headers={"Content-Type": "application/json"}, method="POST", ) ``` Subsequent requests use the same unrestricted API base and transmit the access token: ```python url = f"{API_BASE}/open/v1/create_audio_task" req = urllib.request.Request( url, data=json.dumps(body).encode("utf-8"), headers={"access_token": token, "Content-Type": "application/json"}, method="POST", ) ``` ### Technical Analysis The `CHANJING_API_BASE` environment variable is accepted without validation of its scheme, hostname, port, or destination address. The authentication request sends the long-lived `app_id` and `secret_key` to this endpoint. Later requests send the resulting access token and, during task creation, user-provided TTS text. An attacker who can influence the process environment or launcher configuration can redirect these requests to an attacker-controlled server. The value may also use plaintext HTTP or target a local or internal service. Allowing the authentication destination to be changed this freely exceeds the minimum network privileges required for a client dedicated to the declared Chanjing service. ### Attack Path 1. An attacker, compromised launcher, or unsafe deployment configuration sets `CHANJING_API_BASE` to an attacker-controlled endpoint. 2. The user invokes any included script while the stored token is absent or near expiration. 3. `get_token()` s ...[truncated 750 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions - Enforce `https://open-api.chanjing.cc` as the authentication endpoint. - If API-base overrides are operationally necessary, require explicit opt-in and restrict them to a documented allowlist of trusted HTTPS hosts. - Parse the configured URL and reject: - Schemes other than HTTPS - Embedded usernames or passwords - Unexpected ports - URL fragments - Loopback, link-local, private, multicast, and cloud metadata addresses - Keep token acquisition pinned to the official authentication host even if other API endpoints may be overridden. - Do not send credentials after cross-origin redirects; either disable redirects for authentication or revalidate every redirect destination. - Add automated tests confirming that malicious, plaintext, and internal-network API-base values are rejected. ]]>
