Skip to content

Commit b63cabe

Browse files
committed
dmarc: stop merging multiple TXT records
Closes: #72
1 parent addeefe commit b63cabe

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

dmarc/lookup.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ func IsTempFail(err error) bool {
2424

2525
var ErrNoPolicy = errors.New("dmarc: no policy found for domain")
2626

27+
var errUnsupportedVersion = errors.New("dmarc: unsupported DMARC version")
28+
2729
// LookupOptions allows to customize the default signature verification behavior
2830
// LookupTXT returns the DNS TXT records for the given domain name. If nil, net.LookupTXT is used
2931
type LookupOptions struct {
@@ -51,13 +53,19 @@ func LookupWithOptions(domain string, options *LookupOptions) (*Record, error) {
5153
}
5254
return nil, errors.New("dmarc: failed to lookup TXT record: " + err.Error())
5355
}
54-
if len(txts) == 0 {
55-
return nil, ErrNoPolicy
56+
57+
for _, txt := range txts {
58+
if !strings.HasPrefix(txt, "v=") {
59+
continue
60+
}
61+
record, err := Parse(txt)
62+
if err == errUnsupportedVersion {
63+
continue
64+
}
65+
return record, err
5666
}
5767

58-
// Long keys are split in multiple parts
59-
txt := strings.Join(txts, "")
60-
return Parse(txt)
68+
return nil, ErrNoPolicy
6169
}
6270

6371
func Parse(txt string) (*Record, error) {
@@ -67,7 +75,7 @@ func Parse(txt string) (*Record, error) {
6775
}
6876

6977
if params["v"] != "DMARC1" {
70-
return nil, errors.New("dmarc: unsupported DMARC version")
78+
return nil, errUnsupportedVersion
7179
}
7280

7381
rec := new(Record)

0 commit comments

Comments
 (0)