feat: support system proxy for remote API

This commit is contained in:
Manx98
2026-03-29 22:40:03 +08:00
committed by lyingbug
parent 2d5782992e
commit 1baabb6c05
2 changed files with 23 additions and 1 deletions
+1
View File
@@ -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,
+22 -1
View File
@@ -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
}