From 30d0ddb20db36140b3ccf4fb820dcd95ea9322d4 Mon Sep 17 00:00:00 2001 From: vnxme <46669194+vnxme@users.noreply.github.com> Date: Sun, 11 Aug 2024 22:54:27 +0300 Subject: [PATCH] Fix a regression in #6480: the context may have no replacer (e.g. in TestDefaultSNI) --- 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 83a464713819..f946223741b5 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 {