diff --git a/internal/models/chat/remote_api.go b/internal/models/chat/remote_api.go index 44459127..21d57419 100644 --- a/internal/models/chat/remote_api.go +++ b/internal/models/chat/remote_api.go @@ -22,6 +22,7 @@ import ( // Uses SSRFSafeDialContext to prevent DNS rebinding attacks at the connection layer. var rawHTTPClient = &http.Client{ Transport: &http.Transport{ + Proxy: http.ProxyFromEnvironment, DialContext: secutils.SSRFSafeDialContext, TLSHandshakeTimeout: 10 * time.Second, IdleConnTimeout: 90 * time.Second, diff --git a/internal/utils/security.go b/internal/utils/security.go index 4cb6d9ea..f54e418a 100644 --- a/internal/utils/security.go +++ b/internal/utils/security.go @@ -14,6 +14,8 @@ import ( "sync" "time" "unicode/utf8" + + "golang.org/x/net/http/httpproxy" ) // XSS 防护相关正则表达式 @@ -781,7 +783,7 @@ func SSRFSafeDialContext(ctx context.Context, network, addr string) (net.Conn, e // Whitelisted hosts bypass all dial-time SSRF checks, consistent with // ValidateURLForSSRF which skips IsSSRFSafeURL for whitelisted hosts. - if IsSSRFWhitelisted(host) { + if IsSystemProxy(addr) || IsSSRFWhitelisted(host) { dialer := &net.Dialer{ Timeout: 30 * time.Second, KeepAlive: 30 * time.Second, @@ -978,3 +980,22 @@ func ValidateURLForSSRF(rawURL string) error { } return nil } + +// IsSystemProxy 判断是否为系统代理 +func IsSystemProxy(host string) bool { + proxyCfg := httpproxy.FromEnvironment() + for _, proxyUrl := range []string{ + proxyCfg.HTTPProxy, + proxyCfg.HTTPSProxy, + } { + if proxyUrl == "" { + continue + } + if parse, err := url.Parse(proxyUrl); err == nil { + if parse.Host == host { + return true + } + } + } + return false +}