emersion / go-msgauth

🔏 A Go library and tools for DKIM, DMARC and Authentication-Results
MIT License
162 stars 51 forks source link

dmarc.Lookup() merges multiple TXT records into a single string #57

Closed wttw closed 8 months ago

wttw commented 9 months ago

net.LookupTXT() returns a slice of strings, with one string for each TXT resource record returned. If there are multiple strings inside a TXT record it concatenates those before returning it.

dmarc.LookupWithOptions then concatenates all of those TXT resource records into a single string before parsing it.

If there are multiple TXT records for _dmarc.example.com it'll likely give the wrong response. That's not going to happen in a healthy DNS zone, but it happens occasionally.

I think that correct behaviour would be for dmarc.LookupWithOptions to remove any TXT records that don't start with "v=", then return an error if there are more than one, then parse just the first remaining TXT RR, if any.

emersion commented 9 months ago

Section 6.6.3 says that we should indeed ignore TXT records that do not start with v=.

emersion commented 6 months ago

This actually causes more issues: https://github.com/emersion/go-msgauth/issues/62