From c3336ab655d9337e0822d125f801f5ea57c4ff5f Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sat, 1 Aug 2026 02:27:37 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=9B=A1=EF=B8=8F=20Sentinel:=20[CRITICAL]?= =?UTF-8?q?=20Fix=20SSRF=20in=20addFromDirectURL?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replaces the direct `http.Get` call with a custom `http.Client` that mitigates SSRF by explicitly blocking access to the cloud metadata endpoint (169.254.169.254) using a dialer Control hook. The fix clones the default transport to avoid dropping other default configs. Co-authored-by: himattm <6266621+himattm@users.noreply.github.com> --- internal/plugin/manager.go | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/internal/plugin/manager.go b/internal/plugin/manager.go index 7aad027..92164c8 100644 --- a/internal/plugin/manager.go +++ b/internal/plugin/manager.go @@ -7,6 +7,7 @@ import ( "encoding/json" "fmt" "io" + "net" "net/http" "net/url" "os" @@ -16,6 +17,7 @@ import ( "runtime" "sort" "strings" + "syscall" "time" "github.com/himattm/prism/internal/fsutil" @@ -468,7 +470,27 @@ func (m *Manager) addFromDirectURL(rawURL string) error { return fmt.Errorf("unsupported URL scheme: %s", parsedURL.Scheme) } - resp, err := http.Get(parsedURL.String()) + transport := http.DefaultTransport.(*http.Transport).Clone() + transport.DisableKeepAlives = true + transport.DialContext = (&net.Dialer{ + Control: func(network, address string, c syscall.RawConn) error { + host, _, _ := net.SplitHostPort(address) + if idx := strings.IndexByte(host, '%'); idx != -1 { + host = host[:idx] + } + if ip := net.ParseIP(host); ip != nil && ip.String() == "169.254.169.254" { + return fmt.Errorf("SSRF blocked") + } + return nil + }, + }).DialContext + + secureClient := &http.Client{ + Timeout: 10 * time.Second, + Transport: transport, + } + + resp, err := secureClient.Get(parsedURL.String()) if err != nil { return fmt.Errorf("failed to fetch plugin: %w", err) }