checker: fix @ target resolving to apex via sdk.JoinRelative
A CNAME (or MX/SRV/NS) whose target is "@" was being concatenated literally as "@.<apex>" instead of resolving to the apex itself. Replace the hand-rolled normaliseTarget logic with sdk.JoinRelative, which correctly maps "" and "@" to the origin. Absolute FQDNs (trailing dot, used for external targets) are still stripped before the call so the external-target path is unaffected.
This commit is contained in:
parent
62e85a155e
commit
c4abc1b861
1 changed files with 13 additions and 19 deletions
|
|
@ -155,7 +155,7 @@ func extractPointers(sub, apex string, svc rawService) ([]Pointer, error) {
|
|||
if err := json.Unmarshal(svc.Service, &b); err != nil {
|
||||
return nil, fmt.Errorf("decode cname body: %w", err)
|
||||
}
|
||||
target := normaliseTarget(b.Record.Target, owner, apex)
|
||||
target := normaliseTarget(b.Record.Target, apex)
|
||||
if target == "" {
|
||||
return nil, nil
|
||||
}
|
||||
|
|
@ -175,7 +175,7 @@ func extractPointers(sub, apex string, svc rawService) ([]Pointer, error) {
|
|||
}
|
||||
out := make([]Pointer, 0, len(b.MXs))
|
||||
for _, r := range b.MXs {
|
||||
target := normaliseTarget(r.Mx, owner, apex)
|
||||
target := normaliseTarget(r.Mx, apex)
|
||||
if target == "" {
|
||||
continue
|
||||
}
|
||||
|
|
@ -196,7 +196,7 @@ func extractPointers(sub, apex string, svc rawService) ([]Pointer, error) {
|
|||
}
|
||||
out := make([]Pointer, 0, len(b.Records))
|
||||
for _, r := range b.Records {
|
||||
target := normaliseTarget(r.Target, owner, apex)
|
||||
target := normaliseTarget(r.Target, apex)
|
||||
if target == "" {
|
||||
continue
|
||||
}
|
||||
|
|
@ -218,7 +218,7 @@ func extractPointers(sub, apex string, svc rawService) ([]Pointer, error) {
|
|||
ptOwner := preferRRName(b.Record.Hdr.Name, owner, apex)
|
||||
switch b.Record.Hdr.Rrtype {
|
||||
case dns.TypeNS:
|
||||
target := normaliseTarget(b.Record.Ns, ptOwner, apex)
|
||||
target := normaliseTarget(b.Record.Ns, apex)
|
||||
if target == "" {
|
||||
return nil, nil
|
||||
}
|
||||
|
|
@ -230,7 +230,7 @@ func extractPointers(sub, apex string, svc rawService) ([]Pointer, error) {
|
|||
ServiceType: svc.Type,
|
||||
}}, nil
|
||||
case dns.TypeCNAME:
|
||||
target := normaliseTarget(b.Record.Target, ptOwner, apex)
|
||||
target := normaliseTarget(b.Record.Target, apex)
|
||||
if target == "" {
|
||||
return nil, nil
|
||||
}
|
||||
|
|
@ -242,7 +242,7 @@ func extractPointers(sub, apex string, svc rawService) ([]Pointer, error) {
|
|||
ServiceType: svc.Type,
|
||||
}}, nil
|
||||
case dns.TypeMX:
|
||||
target := normaliseTarget(b.Record.Mx, ptOwner, apex)
|
||||
target := normaliseTarget(b.Record.Mx, apex)
|
||||
if target == "" {
|
||||
return nil, nil
|
||||
}
|
||||
|
|
@ -349,20 +349,14 @@ func preferRRName(rrName, fallback, apex string) string {
|
|||
return rrName + "." + apex
|
||||
}
|
||||
|
||||
// normaliseTarget converts a target to FQDN form; happyDomain stores in-zone targets relative, external ones absolute.
|
||||
func normaliseTarget(target, owner, apex string) string {
|
||||
t := strings.TrimSpace(target)
|
||||
if t == "" {
|
||||
return ""
|
||||
// normaliseTarget converts a target to FQDN form without trailing dot.
|
||||
// Absolute FQDNs (trailing dot) are stripped; relative names and "@" are
|
||||
// resolved against apex via sdk.JoinRelative.
|
||||
func normaliseTarget(target, apex string) string {
|
||||
if t, ok := strings.CutSuffix(strings.TrimSpace(target), "."); ok {
|
||||
return t
|
||||
}
|
||||
if trimmed, ok := strings.CutSuffix(t, "."); ok {
|
||||
return trimmed
|
||||
}
|
||||
// Relative target: anchor under apex (empty apex only occurs in tests that omit domain_name).
|
||||
if apex != "" {
|
||||
return t + "." + apex
|
||||
}
|
||||
return t + "." + owner
|
||||
return sdk.JoinRelative(target, apex)
|
||||
}
|
||||
|
||||
func displaySubdomain(s string) string {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue