History

refactor(proxy): improve SOCKS5 proxy authentication handling

- Added nil check for proxy user credentials to prevent potential nil pointer dereference. - Enhanced authentication logic for SOCKS5 proxies in `proxy_helpers.go` and `proxy.go`.

Luis Pater committed 1 year agov6.0.16

Commit 832268c1 parent f6de2a72 files · +12 −6Browse files

Unified · Split

2 files
  1. internal/runtime/executor/proxy_helpers.go +6 −3
  2. internal/util/proxy.go +6 −3
internal/runtime/executor/proxy_helpers.go+6−3
@@ -87,9 +87,12 @@ func buildProxyTransport(proxyURL string) *http.Transport { · 86 unmodified lines
87 // Handle different proxy schemes87 // Handle different proxy schemes
88 if parsedURL.Scheme == "socks5" {88 if parsedURL.Scheme == "socks5" {
89 // Configure SOCKS5 proxy with optional authentication89 // Configure SOCKS5 proxy with optional authentication
90 username := parsedURL.User.Username()90 var proxyAuth *proxy.Auth
91 password, _ := parsedURL.User.Password()91 if parsedURL.User != nil {
92 proxyAuth := &proxy.Auth{User: username, Password: password}92 username := parsedURL.User.Username()
93 password, _ := parsedURL.User.Password()
94 proxyAuth = &proxy.Auth{User: username, Password: password}
95 }
93 dialer, errSOCKS5 := proxy.SOCKS5("tcp", parsedURL.Host, proxyAuth, proxy.Direct)96 dialer, errSOCKS5 := proxy.SOCKS5("tcp", parsedURL.Host, proxyAuth, proxy.Direct)
94 if errSOCKS5 != nil {97 if errSOCKS5 != nil {
95 log.Errorf("create SOCKS5 dialer failed: %v", errSOCKS5)98 log.Errorf("create SOCKS5 dialer failed: %v", errSOCKS5)
internal/util/proxy.go+6−3
@@ -25,9 +25,12 @@ func SetProxy(cfg *config.SDKConfig, httpClient *http.Client) *http.Client { · 24 unmodified lines
25 // Handle different proxy schemes.25 // Handle different proxy schemes.
26 if proxyURL.Scheme == "socks5" {26 if proxyURL.Scheme == "socks5" {
27 // Configure SOCKS5 proxy with optional authentication.27 // Configure SOCKS5 proxy with optional authentication.
28 username := proxyURL.User.Username()28 var proxyAuth *proxy.Auth
29 password, _ := proxyURL.User.Password()29 if proxyURL.User != nil {
30 proxyAuth := &proxy.Auth{User: username, Password: password}30 username := proxyURL.User.Username()
31 password, _ := proxyURL.User.Password()
32 proxyAuth = &proxy.Auth{User: username, Password: password}
33 }
31 dialer, errSOCKS5 := proxy.SOCKS5("tcp", proxyURL.Host, proxyAuth, proxy.Direct)34 dialer, errSOCKS5 := proxy.SOCKS5("tcp", proxyURL.Host, proxyAuth, proxy.Direct)
32 if errSOCKS5 != nil {35 if errSOCKS5 != nil {
33 log.Errorf("create SOCKS5 dialer failed: %v", errSOCKS5)36 log.Errorf("create SOCKS5 dialer failed: %v", errSOCKS5)