T09 · Insecure Skill Coding Practices
- Location
scripts/imagegen.py:277- Finding
Unrestricted Local File Upload to Remote Object Storage
- Content
View full analysis
Vulnerability Details
File Location:
scripts/imagegen.py, lines 277-312 and 818-819
Vulnerability Type: Arbitrary local file upload
Risk Level: MediumVulnerable Code
python def upload_media(client, file_path): path = Path(file_path) if not path.is_file(): raise SystemExit(f"File does not exist: {file_path}") filename = path.name content_type = guess_mime(str(path)) size = path.stat().st_size token = client.create_upload_token(filename, content_type, size) media_id = token["mediaId"] upload_url = token["upload"]["url"] upload_method = token["upload"].get("method", "PUT") upload_headers = token["upload"].get("headers", {}) with open(str(path), "rb") as f: try: oss_resp = requests.request( upload_method, upload_url, headers=upload_headers, data=f, timeout=300, ) except requests.exceptions.RequestException as e: raise SystemExit( f"Object-storage upload network error: {e}" )The upload command exposes this function without restricting the selected file to an image:
python p = sub.add_parser("upload", help="Upload an image") p.add_argument("--file", required=True)Technical Analysis
The image-generation Skill accepts an arbitrary path and only verifies that it refers to a regular file. It does not enforce an image extension allowlist, inspect the file signature, verify that the detected MIME type is an image, reject symbolic-link traversal, or apply a maximum file-size limit.
The associated
guess_mime()behavior assignsapplication/octet-streamto unknown extensions rather than rejecting them. Consequently, the upload operation is not limited to the image files required by the declared functionality.The function obtains an upload URL from AI-HIVE and then transmits the complete ...[truncated 1703 chars]
- Remediation
View remediation
Remediation Suggestions
- Permit only the image formats supported by the selected model, using a strict extension and MIME allowlist.
- Inspect file signatures with a maintained image-decoding library rather than relying exclusively on filename extensions.
- Reject
application/octet-streamand all non-image MIME types in this image-specific Skill. - Resolve the canonical path and reject symbolic links or paths outside explicitly approved input directories where operationally feasible.
- Enforce model-derived and locally defined file-size limits before requesting an upload token.
- Require explicit user confirmation before uploading files outside the working directory or designated media directories.
- Display the canonical path, detected media type, size, and destination before transmission.
- Keep the generic upload primitive private and expose a validated image-only wrapper through the Skill interface.
