Back to skill

Security audit

image2text

Security checks for vulnerabilities and agentic risk

Overview

This OCR skill is coherent, but it needs review because it can fetch arbitrary web URLs from the agent environment without clear network safeguards.

Install only if you are comfortable with the skill reading user-specified local images and making outbound web requests from the agent machine. Avoid untrusted, internal, localhost, metadata-service, or private-network URLs; prefer local image files or tightly controlled image hosts.

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

Warning
Location
scripts/ocr.py:24
Finding

Unrestricted URL Fetching Enables Server-Side Request Forgery

Content
View full analysis

Vulnerability Details

File Location: scripts/ocr.py, lines 24–35 and 68–82
Vulnerability Type: Server-Side Request Forgery (SSRF) through unrestricted HTTP(S) retrieval
Risk Level: Medium

Vulnerable Code

python
def download_file(url, tmp_path):
    """下载文件到临时路径"""
    try:
        import urllib.request
        urllib.request.urlretrieve(url, tmp_path)
        return tmp_path
    except Exception as e:
        # 尝试 curl
        result = subprocess.run(['curl', '-s', '-o', tmp_path, url], capture_output=True)
        if result.returncode != 0:
            raise Exception(f"下载失败: {e}")
        return tmp_path

The vulnerable function is reached with a user-controlled URL here:

python
if is_url(image_input):
    print(f"[OCR] 检测为 URL,正在下载...", file=sys.stderr)
    suffix = '.png'
    if '.jpg' in image_input or '.jpeg' in image_input:
        suffix = '.jpg'
    elif '.gif' in image_input:
        suffix = '.gif'
    elif '.webp' in image_input:
        suffix = '.webp'

    with tempfile.NamedTemporaryFile(suffix=suffix, delete=False) as f:
        tmp_file = f.name
    download_file(image_input, tmp_file)
    image_path = tmp_file

Technical Analysis

The positional image argument is accepted as a URL whenever it starts with http:// or https://. The URL is then passed directly to urllib.request.urlretrieve. If that operation raises an exception, the same URL is passed to curl.

Neither retrieval path validates the destination hostname or its resolved IP address. Consequently, the caller can direct requests toward loopback, private, link-local, reserved, or cloud metadata network ranges. Redirects are also not explicitly disabled or validated, so a public URL may redirect the request to an internal destination.

The implementation additionally lacks explicit connection/read timeouts, response-size limits, and pre-download content validatio ...[truncated 2320 chars]

Remediation
View remediation

Remediation Suggestions

  1. Prefer an explicit allowlist of trusted image-hosting domains. Reject all other destinations where unrestricted URL support is unnecessary.
  2. Require HTTPS unless plain HTTP is explicitly needed for a trusted destination.
  3. Resolve the destination hostname before connecting and reject every address in loopback, private, link-local, multicast, unspecified, reserved, and other non-public ranges for both IPv4 and IPv6.
  4. Protect against DNS rebinding by ensuring the validated address is the address actually used for the connection. Do not rely only on a one-time hostname string check.
  5. Disable redirects or validate the hostname and resolved addresses at every redirect hop. Set a small maximum redirect count.
  6. Apply strict connection and read timeouts to both the primary downloader and any fallback.
  7. Stream the response while enforcing a maximum byte count rather than downloading an unrestricted body directly to disk.
  8. Validate the response content type and image magic bytes before invoking Tesseract. Do not infer trust or format from a substring in the URL.
  9. Run network retrieval with outbound firewall controls that prevent access to internal and cloud metadata networks.
  10. Avoid maintaining two download implementations with different security behavior. Use one hardened retrieval routine and return a clear error if it fails.
  11. Consider accepting uploaded image bytes through a controlled interface instead of allowing the Skill to retrieve arbitrary URLs.
Vulnerability Patterns
  • Data ExfiltrationExternal Transmission, Env Variable Harvesting, File System Enumeration
  • Trigger AbuseOverly Broad Trigger, Shadow Command Trigger, Keyword Baiting Trigger
  • Behavioral ASTexec() Call, eval() Call, Dynamic Import
  • Prompt InjectionInstruction Override, Hidden Instructions, Exfiltration Commands
  • Privilege EscalationExcessive Permissions, Sudo/Root Execution, Credential Access
Findings (4)

Vague Triggers

Medium
Category
Not specified by scanner
Confidence
88% confidence
Finding

The skill description is very broad ('any image', 'any image-to-text task', 'perfect for text-only AI models') and encourages invocation for a wide range of requests without clearly constraining when local files, remote URLs, or pasted base64 should be used. Overly broad routing increases the chance the agent will trigger this skill on sensitive user content or in situations where network/file access is unnecessary, expanding the attack surface for data exposure and unintended processing.

Content

No source excerpt is available for this finding.

Missing User Warnings

Medium
Category
Not specified by scanner
Confidence
93% confidence
Finding

The documentation states that URLs are automatically downloaded with curl, including OSS/http/https sources, but it does not disclose network access implications or warn that remote resources will be contacted. This can lead to unintended external requests, privacy leaks, and possible access to internal or sensitive endpoints if untrusted URLs are accepted, making the behavior dangerous in an agent environment.

Content

No source excerpt is available for this finding.

subprocess module call

Medium
Category
Dangerous Code Execution
Confidence
84% confidence
Finding

This code downloads arbitrary attacker-supplied URLs, first via urllib and then via curl, enabling server-side request forgery behavior if the skill runs in a networked environment. An attacker can cause requests to internal services, cloud metadata endpoints, or other restricted network locations, and then feed the retrieved content into downstream image parsing/OCR tooling.

Content

Scanner excerpt · scripts/ocr.py (reported line 36)May include surrounding context.

python
return tmp_path
    except Exception as e:
        # 尝试 curl
        result = subprocess.run(['curl', '-s', '-o', tmp_path, url], capture_output=True)
        if result.returncode != 0:
            raise Exception(f"下载失败: {e}")
        return tmp_path

subprocess module call

Medium
Category
Dangerous Code Execution
Confidence
70% confidence
Finding

subprocess module calls execute external commands. Without careful input validation, this enables command injection.

Content

Scanner excerpt · scripts/ocr.py (reported line 44)May include surrounding context.

python
def run_tesseract(image_path, languages='chi_sim+eng', psm=6):
    """运行 tesseract OCR"""
    cmd = ['tesseract', image_path, 'stdout', '--psm', str(psm), '-l', languages]
    result = subprocess.run(cmd, capture_output=True, text=True)
    if result.returncode != 0:
        raise Exception(f"OCR 失败: {result.stderr}")
    return result.stdout