From 7cf8376e638948490be3e9eb5c7d58ce2a4b93b3 Mon Sep 17 00:00:00 2001 From: vnxme <46669194+vnxme@users.noreply.github.com> Date: Mon, 12 Aug 2024 10:01:09 +0300 Subject: [PATCH] matchers: fix a regression in #6480 (#6510) The context may have no replacer --- modules/caddytls/matchers.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/modules/caddytls/matchers.go b/modules/caddytls/matchers.go index 83a46471..f9462237 100644 --- a/modules/caddytls/matchers.go +++ b/modules/caddytls/matchers.go @@ -50,12 +50,13 @@ func (MatchServerName) CaddyModule() caddy.ModuleInfo { // Match matches hello based on SNI. func (m MatchServerName) Match(hello *tls.ClientHelloInfo) bool { + repl := caddy.NewReplacer() // caddytls.TestServerNameMatcher calls this function without any context - var repl *caddy.Replacer if ctx := hello.Context(); ctx != nil { - repl = ctx.Value(caddy.ReplacerCtxKey).(*caddy.Replacer) - } else { - repl = caddy.NewReplacer() + // In some situations the existing context may have no replacer + if replAny := ctx.Value(caddy.ReplacerCtxKey); replAny != nil { + repl = replAny.(*caddy.Replacer) + } } for _, name := range m {