Back to skill

Security audit

image-generator-custom

Security checks for vulnerabilities and agentic risk

Overview

This custom image generator is mostly transparent, but needs review because it can fetch arbitrary image URLs returned by a provider, including unintended internal addresses.

Install only if you trust the configured image API provider and are comfortable sending prompts and request metadata to it. Avoid sensitive prompts, review where images are saved, and prefer providers that return base64 image data or otherwise ensure returned image URLs cannot point to internal or untrusted destinations.

Vulnerability Patterns
  • Insecure Skill Coding PracticesFinds exploitable flaws such as hardcoded secrets or command injection
  • Skill Instruction HijackingAlters the agent's session goals or safety constraints when the skill loads
  • Agent Memory PoisoningWrites attacker-controlled rules into memory that affect later sessions
  • Remote Payload Retrieval and ExecutionFetches external code whose behavior can change after review
  • Embedded Malicious CodeShips malicious scripts inside the skill and executes them locally
Findings (1)

T09 · Insecure Skill Coding Practices

Error
Location
scripts/image_generator.py:171
Finding
Unrestricted Server-Supplied Image URL Enables SSRF<![CDATA[ ## Vulnerability Details **File Location**: `scripts/image_generator.py`, lines 171–180 **Vulnerability Type**: Server-Side Request Forgery (SSRF) through an untrusted response URL **Risk Level**: High ### Vulnerable Code ```python elif "url" in img_data: try: img_url = img_data["url"] print(f"正在下载图像 {i+1}: {img_url}") img_response = requests.get(img_url, timeout=60) if img_response.status_code == 200: saved = save_image(img_response.content, filename) saved_files.append(saved) ``` ### Technical Analysis The configured image-generation service controls the `url` field in its API response. The script passes that value directly to `requests.get()` without validating: - The URL scheme - The destination hostname - The resolved IP address - Redirect destinations - Loopback, private, link-local, reserved, or cloud metadata addresses - Response content type - Response size Although downloading a generated image is part of the declared functionality, unrestricted retrieval from any server exceeds the minimum network access needed. A malicious or compromised API provider could direct the runtime to request internal resources such as `127.0.0.1`, private network services, or cloud metadata endpoints such as `169.254.169.254`. The response is read into memory through `img_response.content` and saved without a size limit or image validation. This additionally permits memory or disk exhaustion and allows arbitrary response content to be stored under a `.png` filename. ### Attack Path 1. A user configures the Skill to use a malicious or compromised OpenAI-compatible image API. 2. The user invokes the image-generation script with a prompt. 3. The API returns a syntactically valid response containing an attacker-selected URL, for example: ```json { "data": [ { "url": "http://169.254.169.254/latest/meta-data/" } ] } ``` 4. The script extracts the URL and performs a GET r ...[truncated 1369 chars]
Remediation
<![CDATA[ ## Remediation Suggestions 1. **Restrict destination hosts** - Permit image downloads only from an explicit allowlist of trusted provider or CDN hostnames. - Do not accept arbitrary hosts solely because the generation API returned them. 2. **Require secure transport** - Allow only `https` URLs. - Reject URLs containing embedded credentials or unexpected ports. 3. **Block internal destinations** - Resolve the hostname before connecting. - Reject loopback, private, link-local, multicast, reserved, unspecified, and cloud metadata IP ranges for both IPv4 and IPv6. - Protect against DNS rebinding by ensuring that the validated address is the address used for the connection. 4. **Control redirects** - Disable automatic redirects or validate the scheme, hostname, port, and resolved address at every redirect hop. - Apply a small redirect limit. 5. **Limit downloaded content** - Use streamed downloads instead of reading the entire response into memory. - Enforce a strict maximum byte count based on expected image dimensions. - Abort if `Content-Length` exceeds the limit or if streamed content crosses it. 6. **Validate file contents** - Require an approved image media type. - Decode and verify the image with Pillow before saving it. - Reject malformed images and unsupported formats rather than relying on the `.png` extension. 7. **Reduce local file risks** - Write only within a designated output directory. - Sanitize the user-controlled output prefix and prevent absolute paths or path traversal. - Use exclusive file creation or randomized filenames to avoid unintended overwrites. A hardened implementation should combine destination allowlisting, IP-range checks, per-redirect validation, streaming size limits, and actual image decoding. Any one of these controls alone is insufficient against redirects, DNS rebinding, or oversized responses. ]]>
Vulnerability Patterns
  • Data ExfiltrationExternal Transmission, Env Variable Harvesting, File System Enumeration
  • MCP Least PrivilegeUnderdeclared Capability, Wildcard Permission, Missing Permission Declaration
  • Prompt InjectionInstruction Override, Hidden Instructions, Exfiltration Commands
  • Privilege EscalationExcessive Permissions, Sudo/Root Execution, Credential Access
  • Supply ChainUnpinned Dependencies, External Script Fetching, Obfuscated Code
Findings (7)

Lp3

Medium
Category
MCP Least Privilege
Confidence
92% confidence
Finding
The skill documents use of environment variables and outbound network access to a third-party API, but it does not declare any explicit tool scope or permissions. This creates a transparency and governance gap: an agent may invoke capabilities beyond what users or platform policy reviewers can easily assess, increasing the risk of unintended secret use and external data transmission.

Missing User Warnings

Medium
Confidence
95% confidence
Finding
The skill’s goal/ability description explains that it calls a third-party image API, but it does not clearly warn users that their prompts and related request data will be transmitted to an external provider. This can lead to inadvertent disclosure of sensitive prompts, proprietary data, or personal information to a non-local service.

External Transmission

Medium
Category
Data Exfiltration
Content
```

### 支持的服务商示例
- OpenAI DALL-E: `https://api.openai.com/v1/images/generations`
- Azure OpenAI: `https://your-resource.openai.azure.com/openai/deployments/your-deployment/images/generations?api-version=2023-06-01-preview`
- 其他兼容 OpenAI 格式的 API 服务商
Confidence
50% confidence
Finding
Data is being sent to an external URL. This could be legitimate telemetry or data exfiltration. Manual review is recommended.

External Transmission

Medium
Category
Data Exfiltration
Content
```

### 支持的服务商示例
- OpenAI DALL-E: `https://api.openai.com/v1/images/generations`
- Azure OpenAI: `https://your-resource.openai.azure.com/openai/deployments/your-deployment/images/generations?api-version=2023-06-01-preview`
- 其他兼容 OpenAI 格式的 API 服务商
Confidence
50% confidence
Finding
Data is being sent to an external URL. This could be legitimate telemetry or data exfiltration. Manual review is recommended.

Natural-Language Policy Violations

Medium
Confidence
95% confidence
Finding
This code file contains natural-language documentation entirely in Chinese, including the module docstring and usage examples, with no indication that the skill is region-specific or that users can opt into another language. Under the policy rule, forcing a specific language without user choice is a natural-language policy violation.

External Transmission

Medium
Category
Data Exfiltration
Content
print(f"模型: {model}")
        print(f"尺寸: {size}, 数量: {n}, 质量: {quality}")
        
        response = requests.post(
            api_url,
            headers=headers,
            json=data,
Confidence
88% confidence
Finding
The skill sends user-supplied prompts and an API bearer token to a configurable third-party endpoint from environment variables, and it also follows provider-returned image URLs with a second outbound request. In this skill context, external transmission is expected, but the lack of allowlisting or validation of the destination makes secret exposure and SSRF-style access to unintended hosts more dangerous if the API URL or returned image URL is malicious or misconfigured.

Missing User Warnings

Low
Confidence
85% confidence
Finding
The skill notes elsewhere that images are saved in the current directory, but it lacks an explicit warning emphasizing local filesystem persistence and the resulting data-handling implications. Users may assume outputs are transient when they are actually written to disk, which can expose sensitive or regulated generated content to other local processes or users.

Static analysis

No suspicious patterns detected.