T09 · Insecure Skill Coding Practices
- Location
scripts/gen.py:143- Finding
Unvalidated API-Provided Image URL Enables Server-Side Request Forgery
- Content
View full analysis
bytes: """Download image bytes from a URL.""" with urllib.request.urlopen(url, timeout=60) as resp: return resp.read() ``` The unvalidated URL is obtained from the remote API in both generation paths: ```python def generate_image(api_key: str, prompt: str) -> bytes: """Generate an image via SkillBoss API Hub (auto-routed).""" result = _pilot(api_key, { "type": "image", "inputs": {"prompt": prompt}, "prefer": "quality", }) image_url = result["result"]["image_url"] return _download_image(image_url) ``` ```python def generate_image_hq(api_key: str, prompt: str, aspect: str) -> bytes: """Generate a high-quality image via SkillBoss API Hub with aspect ratio support.""" inputs = {"prompt": prompt} if aspect and aspect != "1:1": aspect_map = { "16:9": "1536x864", "9:16": "864x1536", "4:3": "1280x960", "3:4": "960x1280", } if aspect in aspect_map: inputs["size"] = aspect_map[aspect] result = _pilot(api_key, { "type": "image", "inputs": inputs, "prefer": "quality", }) image_url = result["result"]["image_url"] return _download_image(image_url) ``` ### Technical Analysis The application trusts `result["result"]["image_url"]` returned by the SkillBoss API and passes it directly to `urllib.request.urlopen`. It does not validate: - The URL scheme. - The destination hostname. - The resolved IP address. - Redirect destinations. - Whether the address belongs to a loopback, private, link-local, or reserved network. - The response content type. - The maximum response size. Consequently, a compromised API, ...[truncated 1671 chars]- Remediation
View remediation
