From 4c63acfbe08503424cc2834cf2a64c8f89c6c3a0 Mon Sep 17 00:00:00 2001 From: Vinicius Fortuna Date: Tue, 26 Sep 2023 16:49:08 -0400 Subject: [PATCH 1/2] Fix HTTP proxy handler --- x/httpproxy/connect_handler.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/x/httpproxy/connect_handler.go b/x/httpproxy/connect_handler.go index cafbf964..bcb85e3d 100644 --- a/x/httpproxy/connect_handler.go +++ b/x/httpproxy/connect_handler.go @@ -15,9 +15,12 @@ package httpproxy import ( + "context" + "fmt" "io" "net" "net/http" + "strings" "github.com/Jigsaw-Code/outline-sdk/transport" ) @@ -124,5 +127,11 @@ func (h *handler) handleConnect(proxyResp http.ResponseWriter, proxyReq *http.Re // The resulting handler is currently vulnerable to probing attacks. It's ok as a localhost proxy // but it may be vulnerable if used as a public proxy. func NewConnectHandler(dialer transport.StreamDialer) http.Handler { - return &handler{dialer, *http.DefaultClient} + dialContext := func(ctx context.Context, network, addr string) (net.Conn, error) { + if !strings.HasPrefix(network, "tcp") { + return nil, fmt.Errorf("protocol not supported: %v", network) + } + return dialer.Dial(ctx, addr) + } + return &handler{dialer, http.Client{Transport: &http.Transport{DialContext: dialContext}}} } From 39117ef235a41b016e8f3dcd3ae052bef949f24f Mon Sep 17 00:00:00 2001 From: Vinicius Fortuna Date: Tue, 26 Sep 2023 18:07:44 -0400 Subject: [PATCH 2/2] Clarify if --- x/httpproxy/connect_handler.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/x/httpproxy/connect_handler.go b/x/httpproxy/connect_handler.go index bcb85e3d..52aa9946 100644 --- a/x/httpproxy/connect_handler.go +++ b/x/httpproxy/connect_handler.go @@ -38,11 +38,12 @@ func (h *handler) ServeHTTP(proxyResp http.ResponseWriter, proxyReq *http.Reques if proxyReq.Method == http.MethodConnect { h.handleConnect(proxyResp, proxyReq) return - } else if proxyReq.URL.Host != "" { + } + if proxyReq.URL.Host != "" { h.handleHTTPProxyRequest(proxyResp, proxyReq) - } else { - http.Error(proxyResp, "Not Found", http.StatusNotFound) + return } + http.Error(proxyResp, "Not Found", http.StatusNotFound) } func (h *handler) handleHTTPProxyRequest(proxyResp http.ResponseWriter, proxyReq *http.Request) {