From 4c516367886014ce98fa17cd8b0f20bd434c6e92 Mon Sep 17 00:00:00 2001 From: yuhan6665 <1588741+yuhan6665@users.noreply.github.com> Date: Sat, 6 Jul 2024 15:06:58 -0400 Subject: [PATCH] Relax server HTTP host check --- transport/internet/http/config.go | 4 +++- transport/internet/httpupgrade/hub.go | 2 +- transport/internet/splithttp/hub.go | 2 +- transport/internet/websocket/hub.go | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/transport/internet/http/config.go b/transport/internet/http/config.go index cfcc8c08..990c2680 100644 --- a/transport/internet/http/config.go +++ b/transport/internet/http/config.go @@ -1,6 +1,8 @@ package http import ( + "strings" + "github.com/xtls/xray-core/common" "github.com/xtls/xray-core/common/dice" "github.com/xtls/xray-core/transport/internet" @@ -18,7 +20,7 @@ func (c *Config) getHosts() []string { func (c *Config) isValidHost(host string) bool { hosts := c.getHosts() for _, h := range hosts { - if h == host { + if strings.Contains(strings.ToLower(host), strings.ToLower(h)) { return true } } diff --git a/transport/internet/httpupgrade/hub.go b/transport/internet/httpupgrade/hub.go index 52e260a4..5be9240f 100644 --- a/transport/internet/httpupgrade/hub.go +++ b/transport/internet/httpupgrade/hub.go @@ -39,7 +39,7 @@ func (s *server) Handle(conn net.Conn) (stat.Connection, error) { if s.config != nil { host := req.Host - if len(s.config.Host) > 0 && host != s.config.Host { + if len(s.config.Host) > 0 && !strings.Contains(strings.ToLower(host), strings.ToLower(s.config.Host)) { return nil, errors.New("bad host: ", host) } path := s.config.GetNormalizedPath() diff --git a/transport/internet/splithttp/hub.go b/transport/internet/splithttp/hub.go index 3dee0b9e..8fe4951f 100644 --- a/transport/internet/splithttp/hub.go +++ b/transport/internet/splithttp/hub.go @@ -72,7 +72,7 @@ func (h *requestHandler) upsertSession(sessionId string) *httpSession { } func (h *requestHandler) ServeHTTP(writer http.ResponseWriter, request *http.Request) { - if len(h.host) > 0 && request.Host != h.host { + if len(h.host) > 0 && !strings.Contains(strings.ToLower(request.Host), strings.ToLower(h.host)) { errors.LogInfo(context.Background(), "failed to validate host, request:", request.Host, ", config:", h.host) writer.WriteHeader(http.StatusNotFound) return diff --git a/transport/internet/websocket/hub.go b/transport/internet/websocket/hub.go index 2fb893b2..1d86be1d 100644 --- a/transport/internet/websocket/hub.go +++ b/transport/internet/websocket/hub.go @@ -38,7 +38,7 @@ var upgrader = &websocket.Upgrader{ } func (h *requestHandler) ServeHTTP(writer http.ResponseWriter, request *http.Request) { - if len(h.host) > 0 && request.Host != h.host { + if len(h.host) > 0 && !strings.Contains(strings.ToLower(request.Host), strings.ToLower(h.host)) { errors.LogInfo(context.Background(), "failed to validate host, request:", request.Host, ", config:", h.host) writer.WriteHeader(http.StatusNotFound) return