From 5aa053a65fd8888a2a7c8c32ab12e0afe89ebb06 Mon Sep 17 00:00:00 2001 From: Arthur Morgan Date: Fri, 22 Jan 2021 07:37:55 +0800 Subject: [PATCH] Convert domain names to lowercase before matching (#195) Co-authored-by: RPRX <63339210+rprx@users.noreply.github.com> --- app/dns/server.go | 1 + app/router/condition.go | 2 +- common/protocol/tls/sniff.go | 2 +- proxy/trojan/server.go | 2 ++ proxy/vless/inbound/inbound.go | 2 ++ 5 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app/dns/server.go b/app/dns/server.go index 667b398e..82f9d23e 100644 --- a/app/dns/server.go +++ b/app/dns/server.go @@ -364,6 +364,7 @@ func (s *Server) lookupIPInternal(domain string, option IPOption) ([]net.IP, err if domain == "" { return nil, newError("empty domain name") } + domain = strings.ToLower(domain) // normalize the FQDN form query if domain[len(domain)-1] == '.' { diff --git a/app/router/condition.go b/app/router/condition.go index 341cb566..8c5d1de8 100644 --- a/app/router/condition.go +++ b/app/router/condition.go @@ -91,7 +91,7 @@ func (m *DomainMatcher) Apply(ctx routing.Context) bool { if len(domain) == 0 { return false } - return m.ApplyDomain(domain) + return m.ApplyDomain(strings.ToLower(domain)) } type MultiGeoIPMatcher struct { diff --git a/common/protocol/tls/sniff.go b/common/protocol/tls/sniff.go index a8fec15f..f3806a05 100644 --- a/common/protocol/tls/sniff.go +++ b/common/protocol/tls/sniff.go @@ -102,7 +102,7 @@ func ReadClientHello(data []byte, h *SniffHeader) error { return errNotClientHello } if nameType == 0 { - serverName := string(d[:nameLen]) + serverName := strings.ToLower(string(d[:nameLen])) // An SNI value may not include a // trailing dot. See // https://tools.ietf.org/html/rfc6066#section-3. diff --git a/proxy/trojan/server.go b/proxy/trojan/server.go index 6b22e49e..4871524f 100644 --- a/proxy/trojan/server.go +++ b/proxy/trojan/server.go @@ -412,6 +412,8 @@ func (s *Server) fallback(ctx context.Context, sid errors.ExportOption, err erro newError("realName = " + name).AtInfo().WriteToLog(sid) newError("realAlpn = " + alpn).AtInfo().WriteToLog(sid) } + name = strings.ToLower(name) + alpn = strings.ToLower(alpn) if len(napfb) > 1 || napfb[""] == nil { if name != "" && napfb[name] == nil { diff --git a/proxy/vless/inbound/inbound.go b/proxy/vless/inbound/inbound.go index 264f1e1f..8766d391 100644 --- a/proxy/vless/inbound/inbound.go +++ b/proxy/vless/inbound/inbound.go @@ -232,6 +232,8 @@ func (h *Handler) Process(ctx context.Context, network net.Network, connection i newError("realName = " + name).AtInfo().WriteToLog(sid) newError("realAlpn = " + alpn).AtInfo().WriteToLog(sid) } + name = strings.ToLower(name) + alpn = strings.ToLower(alpn) if len(napfb) > 1 || napfb[""] == nil { if name != "" && napfb[name] == nil {