Skip to content

Commit

Permalink
caddytls: Refactor sni matcher (#6812)
Browse files Browse the repository at this point in the history
  • Loading branch information
vnxme authored Jan 27, 2025
1 parent 066d770 commit d7872c3
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion modules/caddytls/matchers.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (MatchServerName) CaddyModule() caddy.ModuleInfo {

// Match matches hello based on SNI.
func (m MatchServerName) Match(hello *tls.ClientHelloInfo) bool {
repl := caddy.NewReplacer()
var repl *caddy.Replacer
// caddytls.TestServerNameMatcher calls this function without any context
if ctx := hello.Context(); ctx != nil {
// In some situations the existing context may have no replacer
Expand All @@ -65,6 +65,10 @@ func (m MatchServerName) Match(hello *tls.ClientHelloInfo) bool {
}
}

if repl == nil {
repl = caddy.NewReplacer()
}

for _, name := range m {
rs := repl.ReplaceAll(name, "")
if certmagic.MatchWildcard(hello.ServerName, rs) {
Expand Down

0 comments on commit d7872c3

Please sign in to comment.