T09 · Insecure Skill Coding Practices
- Location
scripts/text-to-image/impl.py:179- Finding
Bearer API Key Disclosure Through Arbitrary Image URLs in Text-to-Image Downloads
- Content
View full analysis
Vulnerability Details
File Location:
scripts/text-to-image/impl.py, lines 179-204
Vulnerability Type: Credential disclosure through untrusted download URLs
Risk Level: HighVulnerable Code
python domain = result.get("domain", "https://file.shortart.ai/") images = result["images"] downloaded = [] download_dir = Path.home() / "Downloads" download_dir.mkdir(exist_ok=True) timestamp = datetime.now().strftime("%Y%m%d_%H%M%S") headers = {} if api_key: headers["Authorization"] = f"Bearer {api_key}" for idx, img in enumerate(images, 1): url = img.get("url") or f"{domain}{img['path']}" ext = Path(img["path"]).suffix or ".jpg" filename = f"shortart_{timestamp}_{idx}{ext}" filepath = download_dir / filename try: resp = requests.get(url, headers=headers, timeout=60) resp.raise_for_status() with open(filepath, "wb") as f: f.write(resp.content)Technical Analysis
The
--downloadmode parses caller-supplied JSON and trusts thedomainand per-imageurlfields. The downloader then attachesSHORTART_API_KEYas a bearer token to every resulting URL without verifying the scheme, hostname, port, or redirect destination.An attacker can provide a successful-looking result object containing a URL under their control. When the documented download workflow processes it, the HTTP request discloses the API key in its
Authorizationheader. Therequestslibrary also follows redirects by default, so an initially trusted URL could redirect the credential-bearing request to another origin.Authentication credentials should only be sent to the service for which they were issued. Downloading generated images does not justify forwarding the API credential to arbitrary destinations.
Attack Path
- An attacker supplies or causes the Agent to process a JSON object with
"status": "success"and a nonemptyimagesarray. ...[truncated 864 chars]
- An attacker supplies or causes the Agent to process a JSON object with
- Remediation
View remediation
Remediation Suggestions
- Do not include the ShortArt bearer token when downloading public or presigned image URLs.
- If authenticated downloads are required, parse URLs with
urllib.parse.urlparseand allowlist exact HTTPS origins controlled by ShortArt. - Reject non-HTTPS schemes, embedded credentials, unexpected ports, malformed hosts, and all non-allowlisted hostnames.
- Disable redirects with
allow_redirects=False, or validate every redirect destination and remove authorization headers before any cross-origin redirect. - Prefer obtaining download URLs directly from a trusted API response rather than accepting complete download-result JSON from command-line input.
- Add tests proving that attacker-controlled URLs and redirects never receive the bearer token.
