mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-02-03 04:50:52 +08:00
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`.
This commit is contained in:
@@ -87,9 +87,12 @@ func buildProxyTransport(proxyURL string) *http.Transport {
|
|||||||
// Handle different proxy schemes
|
// Handle different proxy schemes
|
||||||
if parsedURL.Scheme == "socks5" {
|
if parsedURL.Scheme == "socks5" {
|
||||||
// Configure SOCKS5 proxy with optional authentication
|
// Configure SOCKS5 proxy with optional authentication
|
||||||
|
var proxyAuth *proxy.Auth
|
||||||
|
if parsedURL.User != nil {
|
||||||
username := parsedURL.User.Username()
|
username := parsedURL.User.Username()
|
||||||
password, _ := parsedURL.User.Password()
|
password, _ := parsedURL.User.Password()
|
||||||
proxyAuth := &proxy.Auth{User: username, Password: password}
|
proxyAuth = &proxy.Auth{User: username, Password: password}
|
||||||
|
}
|
||||||
dialer, errSOCKS5 := proxy.SOCKS5("tcp", parsedURL.Host, proxyAuth, proxy.Direct)
|
dialer, errSOCKS5 := proxy.SOCKS5("tcp", parsedURL.Host, proxyAuth, proxy.Direct)
|
||||||
if errSOCKS5 != nil {
|
if errSOCKS5 != nil {
|
||||||
log.Errorf("create SOCKS5 dialer failed: %v", errSOCKS5)
|
log.Errorf("create SOCKS5 dialer failed: %v", errSOCKS5)
|
||||||
|
|||||||
@@ -25,9 +25,12 @@ func SetProxy(cfg *config.SDKConfig, httpClient *http.Client) *http.Client {
|
|||||||
// Handle different proxy schemes.
|
// Handle different proxy schemes.
|
||||||
if proxyURL.Scheme == "socks5" {
|
if proxyURL.Scheme == "socks5" {
|
||||||
// Configure SOCKS5 proxy with optional authentication.
|
// Configure SOCKS5 proxy with optional authentication.
|
||||||
|
var proxyAuth *proxy.Auth
|
||||||
|
if proxyURL.User != nil {
|
||||||
username := proxyURL.User.Username()
|
username := proxyURL.User.Username()
|
||||||
password, _ := proxyURL.User.Password()
|
password, _ := proxyURL.User.Password()
|
||||||
proxyAuth := &proxy.Auth{User: username, Password: password}
|
proxyAuth = &proxy.Auth{User: username, Password: password}
|
||||||
|
}
|
||||||
dialer, errSOCKS5 := proxy.SOCKS5("tcp", proxyURL.Host, proxyAuth, proxy.Direct)
|
dialer, errSOCKS5 := proxy.SOCKS5("tcp", proxyURL.Host, proxyAuth, proxy.Direct)
|
||||||
if errSOCKS5 != nil {
|
if errSOCKS5 != nil {
|
||||||
log.Errorf("create SOCKS5 dialer failed: %v", errSOCKS5)
|
log.Errorf("create SOCKS5 dialer failed: %v", errSOCKS5)
|
||||||
|
|||||||
Reference in New Issue
Block a user