T09 · Insecure Skill Coding Practices
- Location
scripts/bailian_image_gen.py:153- Finding
DashScope API Credential Sent to an Unvalidated Response-Controlled URL
- Content
View full analysis
Vulnerability Details
File Location:
scripts/bailian_image_gen.py:153-155,scripts/comfyui_bailian_node.py:91-93, andscripts/comfyui_bailian_node.py:157-159
Vulnerability Type: Credential disclosure through an unvalidated outbound destination
Risk Level: MediumVulnerable Code
scripts/bailian_image_gen.py:152-161:python def download_image(self, image_url: str, output_path: str) -> str: headers = {"Authorization": f"Bearer {self.api_key}"} response = requests.get(image_url, headers=headers, timeout=60) response.raise_for_status() with open(output_path, "wb") as f: f.write(response.content) return output_pathscripts/comfyui_bailian_node.py:86-93:python print(f"[BailianNode] Image URL: {image_url[:60]}...") import requests headers = {"Authorization": f"Bearer {client.api_key}"} img_response = requests.get(image_url, headers=headers, timeout=60) img_response.raise_for_status()scripts/comfyui_bailian_node.py:152-159:python print(f"[BailianNode] Image URL: {image_url[:60]}...") import requests headers = {"Authorization": f"Bearer {client.api_key}"} img_response = requests.get(image_url, headers=headers, timeout=60) img_response.raise_for_status()Technical Analysis
The image URL is extracted from a remote API response without validating its scheme, hostname, port, or resolved address. The code then sends the DashScope bearer credential to that URL in an
Authorizationheader.Consequently, the credential is not restricted to the intended Alibaba Cloud service boundary. If the API response is compromised or otherwise contains a malicious URL, the client can send the API key to an attacker-controlled server. A URL resolving to a loopback, link-local, or private address could also cause a server-side request forgery-style request from the host running the Skill.
Downloading generated ...[truncated 1558 chars]
- Remediation
View remediation
Remediation Suggestions
- Parse returned URLs with
urllib.parse.urlsplit. - Require the
httpsscheme and reject embedded credentials, unexpected ports, fragments, malformed hostnames, and non-absolute URLs. - Maintain an explicit allowlist of documented Alibaba Cloud image-delivery hostnames. Compare normalized hostnames exactly or use carefully bounded subdomain checks.
- Resolve the hostname and reject loopback, private, link-local, multicast, reserved, and unspecified IP addresses. Revalidate redirects and DNS resolution to reduce redirect and DNS-rebinding risks.
- Disable automatic redirects or validate every redirect target before following it.
- Attach the bearer token only when the validated destination is documented to require DashScope authentication. Otherwise, download the signed URL without an
Authorizationheader. - Centralize image downloading in the hardened
download_image()method so the two ComfyUI nodes do not duplicate unsafe request logic. - Apply response-size and content-type limits before loading or writing downloaded data.
- Parse returned URLs with
