check for domain ownership via subdomain rather than naked domain

This commit is contained in:
Alisdair MacLeod
2026-02-03 12:50:25 +00:00
parent 146774860b
commit 3af4543e80

View File

@@ -25,8 +25,8 @@ func NewValidator(resolver resolver) *Validator {
}
}
// IsValid looks up the CNAME record for the passed domain and compares it
// against the acceptable domains.
// IsValid looks up the CNAME record for the passed domain with a prefix
// and compares it against the acceptable domains.
// If the returned CNAME matches any accepted domain, it will return true,
// otherwise, including in the event of a DNS error, it will return false.
// The comparison is very simple, so wildcards will not match if included
@@ -36,7 +36,10 @@ func (v *Validator) IsValid(ctx context.Context, domain string, accept []string)
v.resolver = net.DefaultResolver
}
cname, err := v.resolver.LookupCNAME(ctx, domain)
// Prepend subdomain for ownership validation because we want to check
// for the record being a wildcard ("*.example.com"), but you cannot
// look up a wildcard so we have to add a subdomain for the check.
cname, err := v.resolver.LookupCNAME(ctx, "validation."+domain)
if err != nil {
log.WithFields(log.Fields{
"domain": domain,