ValiMail / authentication-headers

library for the generation of email authentication headers
Other
16 stars 4 forks source link

IndexError: list index out of range when checking dmarc for certain dmarc records. #26

Closed msapiro closed 9 months ago

msapiro commented 11 months ago

authheaders.dmarc_lookup.answer_to_dict() throws IndexError: list index out of range if given a string ending with an empty quoted value. Examples of dmark records which throw this error are:

_dmarc.wheaton.edu. 3600    IN  TXT "v=DMARC1; p=none; rua=mailto:dmarc.wheaton.rua@wheaton.edu,mailto:dmarc_agg@waybettermarketing.com; ruf=mailto:dmarc.wheaton.ruf@wheaton.edu,mailto:dmarc_fr@waybettermarketing.com; fo=1;" ""

and

_dmarc.virginia.edu.    3600    IN  TXT "v=DMARC1; p=reject; rua=mailto:nw0e7asu@ag.us.dmarcian.com; ruf=mailto:nw0e7asu@fr.us.dmarcian.com; sp=none;" "" ""
msapiro commented 11 months ago

I suggest the following:

--- dmarc_lookup.py 2023-03-08 19:37:24.261341382 -0800
+++ new_dmarc_lookup.py 2023-11-20 12:05:14.118711378 -0800
@@ -37,7 +37,7 @@
 def answer_to_dict(answer):
     # type: (Text) -> Dict[unicode, unicode]
     '''Turn the DNS DMARC answer into a dict of tag:value pairs.'''
-    a = answer.strip('"').strip(' ')
+    a = answer.strip('" ')
     rawTags = [t.split('=') for t in a.split(';') if t]
     retval = {t[0].strip().lower(): t[1].strip().lower() for t in rawTags}
     # Simpler to lowercase everything and put 'v' back.  Already validated

to strip all leading and trailing quotes and spaces instead of just stripping leading and trailing quotes followed by stripping leading and trailing spaces

kitterma commented 9 months ago

Fixed in 0.16.0.