[Upstream] fix(security): prevent SSRF in image URL fetching#130
Open
Sagit-chu wants to merge 1 commit into
Open
[Upstream] fix(security): prevent SSRF in image URL fetching#130Sagit-chu wants to merge 1 commit into
Sagit-chu wants to merge 1 commit into
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Synced from upstream PR: songquanpeng#2390
Summary
GetImageFromUrl()to prevent Server-Side Request Forgery (SSRF) attacksIsPrivateIP()helper tocommon/networkpackageUserContentRequestHTTPClientinstead of barehttp.Get()Bug
GetImageFromUrl()incommon/image/image.gocalledhttp.Get(url)with zero URL validation. Any authenticated user could supply animage_urlpointing to internal/private IP addresses (e.g.169.254.169.254for AWS metadata,127.0.0.1,10.x.x.x), enabling:This affects vision API calls through multiple adaptors (Anthropic, Ollama, Gemini).
Changes
common/network/ip.go: AddIsPrivateIP()that checks for loopback, link-local, RFC 1918, and IPv6 unique local ranges.common/image/image.go: AddvalidateImageUrl()that parses the URL, resolves the hostname, and rejects any IP in a private/reserved range. Applied before any HTTP request inGetImageFromUrl().http.Get()withclient.UserContentRequestHTTPClient.Get()for consistent proxy/timeout behavior.Related: songquanpeng#2388, songquanpeng#2387
Test plan
127.0.0.1,10.x.x.x,169.254.x.xare rejectedgo vet ./common/...to confirm no issues🤖 Generated with Claude Code