From ddb32ef86fbbfe85dfe1a4fb4b5bedf3261b5b97 Mon Sep 17 00:00:00 2001 From: Rohit Lohar <64224488+rohitlohar45@users.noreply.github.com> Date: Fri, 28 Mar 2025 16:06:04 +0530 Subject: [PATCH] Allow underscore character in hostSNI matcher --- pkg/muxer/tcp/mux.go | 2 +- pkg/muxer/tcp/mux_test.go | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/pkg/muxer/tcp/mux.go b/pkg/muxer/tcp/mux.go index 5bf4fbc08..8302ab340 100644 --- a/pkg/muxer/tcp/mux.go +++ b/pkg/muxer/tcp/mux.go @@ -310,7 +310,7 @@ func alpn(tree *matchersTree, protos ...string) error { return nil } -var hostOrIP = regexp.MustCompile(`^[[:alnum:]\.\-\:]+$`) +var hostOrIP = regexp.MustCompile(`^[[:word:]\.\-\:]+$`) // hostSNI checks if the SNI Host of the connection match the matcher host. func hostSNI(tree *matchersTree, hosts ...string) error { diff --git a/pkg/muxer/tcp/mux_test.go b/pkg/muxer/tcp/mux_test.go index 45820acdb..aa3c6b1e6 100644 --- a/pkg/muxer/tcp/mux_test.go +++ b/pkg/muxer/tcp/mux_test.go @@ -743,6 +743,11 @@ func Test_HostSNI(t *testing.T) { ruleHosts: []string{"foo.bar"}, serverName: "foo.bar", }, + { + desc: "Matching hosts with subdomains with _", + ruleHosts: []string{"foo_bar.example.com"}, + serverName: "foo_bar.example.com", + }, { desc: "Matching IPv4", ruleHosts: []string{"127.0.0.1"},