Skip to content

fix(security): prevent SSRF in image URL fetching#2390

Open
hobostay wants to merge 1 commit into
songquanpeng:mainfrom
hobostay:fix/ssrf-image-url
Open

fix(security): prevent SSRF in image URL fetching#2390
hobostay wants to merge 1 commit into
songquanpeng:mainfrom
hobostay:fix/ssrf-image-url

Conversation

@hobostay

Copy link
Copy Markdown

Summary

  • Add URL validation to GetImageFromUrl() to prevent Server-Side Request Forgery (SSRF) attacks
  • Add IsPrivateIP() helper to common/network package
  • Use UserContentRequestHTTPClient instead of bare http.Get()

Bug

GetImageFromUrl() in common/image/image.go called http.Get(url) with zero URL validation. Any authenticated user could supply an image_url pointing to internal/private IP addresses (e.g. 169.254.169.254 for AWS metadata, 127.0.0.1, 10.x.x.x), enabling:

  • Cloud credential theft
  • Internal network scanning
  • Access to internal services

This affects vision API calls through multiple adaptors (Anthropic, Ollama, Gemini).

Changes

  1. common/network/ip.go: Add IsPrivateIP() that checks for loopback, link-local, RFC 1918, and IPv6 unique local ranges.
  2. common/image/image.go: Add validateImageUrl() that parses the URL, resolves the hostname, and rejects any IP in a private/reserved range. Applied before any HTTP request in GetImageFromUrl().
  3. Also replaced http.Get() with client.UserContentRequestHTTPClient.Get() for consistent proxy/timeout behavior.

Related: #2388, #2387

Test plan

  • Verify vision API still works with legitimate external image URLs
  • Verify that URLs pointing to 127.0.0.1, 10.x.x.x, 169.254.x.x are rejected
  • Verify data URLs (base64) still work (not affected by validation)
  • Run go vet ./common/... to confirm no issues

🤖 Generated with Claude Code

GetImageFromUrl() called http.Get() with no URL validation, allowing
authenticated users to supply image_url pointing to internal/private
IP addresses (e.g. 169.254.169.254 for cloud metadata, 127.0.0.1,
10.x.x.x), enabling SSRF attacks.

Changes:
- Add IsPrivateIP() to common/network for checking private/reserved IPs
- Add validateImageUrl() that resolves hostname and rejects private IPs
- Use the configured UserContentRequestHTTPClient instead of default
- Apply validation in GetImageFromUrl before making HTTP requests

Related: songquanpeng#2388, songquanpeng#2387

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant