From d3ad171761bdbf56607abafa913a41fa40e3dfe7 Mon Sep 17 00:00:00 2001 From: Toby Date: Fri, 7 Aug 2020 18:36:13 -0700 Subject: [PATCH] Disable HTTP auth when no username/password is set --- cmd/proxy_client.go | 13 +++++++------ pkg/http/server.go | 4 +++- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/cmd/proxy_client.go b/cmd/proxy_client.go index 770c72c..51b0d36 100644 --- a/cmd/proxy_client.go +++ b/cmd/proxy_client.go @@ -147,6 +147,12 @@ func proxyClient(args []string) { if len(config.HTTPAddr) > 0 { go func() { + var authFunc func(user, password string) bool + if config.HTTPUser != "" && config.HTTPPassword != "" { + authFunc = func(user, password string) bool { + return config.HTTPUser == user && config.HTTPPassword == password + } + } proxy, err := hyHTTP.NewProxyHTTPServer(client, time.Duration(config.HTTPTimeout)*time.Second, aclEngine, func(reqAddr string, action acl.Action, arg string) { logrus.WithFields(logrus.Fields{ @@ -154,12 +160,7 @@ func proxyClient(args []string) { "dst": reqAddr, }).Debug("New HTTP request") }, - func(user, password string) bool { - if config.HTTPUser == "" || config.HTTPPassword == "" { - return true - } - return config.HTTPUser == user && config.HTTPPassword == password - }) + authFunc) if err != nil { logrus.WithField("error", err).Fatal("HTTP server initialization failed") } diff --git a/pkg/http/server.go b/pkg/http/server.go index dc64a04..c07c0fd 100644 --- a/pkg/http/server.go +++ b/pkg/http/server.go @@ -57,7 +57,9 @@ func NewProxyHTTPServer(hyClient core.Client, idleTimeout time.Duration, aclEngi //TLSNextProto: make(map[string]func(authority string, c *tls.Conn) http.RoundTripper), } proxy.ConnectDial = nil - auth.ProxyBasic(proxy, "hysteria client", basicAuthFunc) + if basicAuthFunc != nil { + auth.ProxyBasic(proxy, "hysteria client", basicAuthFunc) + } return proxy, nil }