T09 · Insecure Skill Coding Practices
- Location
scripts/music_gen.py:82- Finding
Unvalidated Server-Provided Download URL Enables SSRF
- Content
View full analysis
Vulnerability Details
File Location:
scripts/music_gen.py, lines 82-92
Vulnerability Type: Server-Side Request Forgery through an unvalidated download URL
Risk Level: MediumVulnerable Code
python def download_music(file_id: str, output_path: str): """下载音乐文件""" url = f"{API_HOST}/v1/files/retrieve" params = {"file_id": file_id} resp = requests.get(url, headers=HEADERS, params=params, timeout=30) resp.raise_for_status() download_url = resp.json()["file"]["download_url"] print(f"📥 正在下载音乐至 {output_path}...") with open(output_path, "wb") as f: vr = requests.get(download_url, timeout=120) vr.raise_for_status() f.write(vr.content)Technical Analysis
The download URL is taken directly from the MiniMax API response and passed to
requests.get()without validating its scheme, hostname, resolved IP address, port, or redirect chain. Redirects are followed by default.If the upstream API, its account context, or the communication response is compromised, an attacker could provide a URL targeting resources reachable from the machine running the skill. Potential targets include loopback services, private network addresses, link-local services, and cloud instance metadata endpoints.
The authorization header containing the MiniMax API key is not included in this second request, which limits direct credential disclosure. However, the response body from the attacker-selected destination is written to the caller-selected output file.
Attack Path
- The user invokes music generation with a chosen output path.
- The script requests file metadata from the fixed MiniMax API endpoint.
- An attacker who controls or compromises the relevant API response supplies an internal URL, such as a loopback, private-network, or cloud metadata address, in
file.download_url. - Alternatively, the attacker supplies an external URL that redire ...[truncated 767 chars]
- Remediation
View remediation
Remediation Suggestions
- Require download URLs to use HTTPS.
- Allowlist the documented MiniMax download hostnames rather than accepting arbitrary hosts.
- Reject URLs containing embedded credentials, unexpected ports, fragments, or malformed hostnames.
- Resolve the destination hostname and reject loopback, private, link-local, multicast, reserved, and unspecified IP ranges for both IPv4 and IPv6.
- Disable redirects with
allow_redirects=False, or validate every redirect destination before following it. - Stream the response instead of loading it entirely into memory, and enforce a maximum permitted download size.
- Verify the returned content type and, where supported, its expected checksum before writing it to disk.
- Open the output file only after the URL and initial response have passed validation.
