T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/image_generate.py:188
- Finding
- Unrestricted DashScope Endpoint Override Can Expose API Credentials and User Content<![CDATA[ ## Vulnerability Details **File Location**: `scripts/env.py:39-40`, `scripts/image_generate.py:145-145, 188-188, 206-206`, `scripts/ocr_text.py:50-50, 61-61, 70-73`, `scripts/tts_speak.py:53-53, 77-83` **Vulnerability Type**: Unvalidated credential-bearing API endpoint override **Risk Level**: High ### Vulnerable Code ```python # scripts/env.py:39-40 def get_region_base_url(env_path: Optional[Path] = None) -> str: return _get_value("DASHSCOPE_BASE_URL", env_path) or DEFAULT_BASE_URL ``` ```python # scripts/image_generate.py response = dashscope.MultiModalConversation.call( api_key=get_dashscope_key(env_path=env_path), model=model, messages=messages, result_format="message", stream=False, watermark=False, prompt_extend=True, negative_prompt=negative_prompt or DEFAULT_NEGATIVE_PROMPT, size=build_size(width, height), ) parser.add_argument( "--base-url", default=None, help="Override DashScope base URL", ) dashscope.base_http_api_url = ( args.base_url or get_region_base_url(env_path=args.config) ) ``` ```python # scripts/ocr_text.py resp = dashscope.MultiModalConversation.call( api_key=get_dashscope_key(), model=model, messages=messages, ocr_options={"task": "text_recognition"}, ) parser.add_argument("--base-url", default=None) if args.base_url: dashscope.base_http_api_url = args.base_url else: dashscope.base_http_api_url = get_region_base_url() ``` ```python # scripts/tts_speak.py resp = dashscope.audio.qwen_tts.SpeechSynthesizer.call( api_key=get_dashscope_key(), **kwargs, ) parser.add_argument("--base-url", default=None) if args.base_url: dashscope.base_http_api_url = args.base_url else: dashscope.base_http_api_url = get_region_base_url() ``` ### Technical Analysis The three service clients permit the DashScope base URL to be supplied through either a command-line argument or the `DASHSCOPE_BASE_URL` configuration value. The supplied URL is assign ...[truncated 1965 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Remove `--base-url` from normal user-facing operation unless endpoint customization is a required feature. 2. Enforce HTTPS for every credential-bearing API request. 3. Parse the endpoint with `urllib.parse.urlparse` and reject: - HTTP and other non-HTTPS schemes - Embedded usernames or passwords - Missing hostnames - IP literals - Loopback, link-local, private, and reserved destinations 4. Maintain an explicit allowlist of supported DashScope hostnames, such as the documented Aliyun endpoint. 5. Apply the same validation to `DASHSCOPE_BASE_URL` loaded from configuration. 6. Require a separate explicit opt-in for nonstandard enterprise endpoints and avoid sending production credentials until the endpoint has been approved. 7. Add tests confirming that HTTP, unapproved hosts, localhost, private IP addresses, and malformed URLs are rejected. 8. Use separate restricted API keys with minimum quotas and permissions, and rotate any key that may have been exposed through an untrusted endpoint. ]]>
