T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/realtime_tts_demo.py:91
- Finding
- User-Controlled API Endpoint Can Receive Credentials and Synthesis Content<![CDATA[ ## Vulnerability Details **File Location**: `scripts/realtime_tts_demo.py:91-98`, `scripts/realtime_tts_demo.py:158-165`, and `scripts/realtime_tts_demo.py:214` **Vulnerability Type**: Arbitrary credential transmission endpoint **Risk Level**: High ### Vulnerable Code ```python def _probe_realtime( text: str, voice: str, instruction: str | None, language_type: str, base_url: str, ) -> dict[str, Any]: dashscope.base_http_api_url = base_url try: stream = dashscope.MultiModalConversation.call( model=REALTIME_MODEL, api_key=os.getenv("DASHSCOPE_API_KEY"), text=text, voice=voice, instruction=instruction, language_type=language_type, stream=True, ) ``` The fallback path has the same behavior: ```python def _fallback_generate( text: str, voice: str, instruction: str | None, language_type: str, base_url: str, output: Path, ) -> dict[str, Any]: dashscope.base_http_api_url = base_url response = dashscope.MultiModalConversation.call( model=FALLBACK_MODEL, api_key=os.getenv("DASHSCOPE_API_KEY"), text=text, voice=voice, instruction=instruction, language_type=language_type, stream=False, ) ``` The destination is controlled through a command-line argument: ```python parser.add_argument( "--base-url", default="https://dashscope.aliyuncs.com/api/v1", ) ``` ### Technical Analysis The command-line `--base-url` value is assigned directly to the DashScope SDK's global API URL without validating its scheme, hostname, port, or ownership. The script then explicitly supplies `DASHSCOPE_API_KEY` to the SDK request together with the text, voice, language, and synthesis instruction. Although sending an API key to Alibaba Cloud is necessary for the declared TTS functionality, allowing an arbitrary destination exceeds the minimum privilege and trus ...[truncated 1386 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Remove `--base-url` if endpoint customization is not essential. 2. If customization is required, parse the URL and enforce: - The `https` scheme. - An explicit allowlist of documented Alibaba Cloud API hostnames. - No embedded username or password. - No unexpected ports. - No IP-literal, loopback, private, or link-local destinations. 3. Validate the effective destination before loading or passing the API key. 4. Ensure the HTTP client does not follow redirects to destinations outside the allowlist. 5. Prefer a fixed regional endpoint selected through a constrained region enumeration rather than a free-form URL. 6. Avoid global SDK endpoint mutation where possible; use a request-scoped, validated client configuration. 7. Document that API credentials and synthesis text are transmitted only to the approved Alibaba Cloud service. ]]>
