Skip to content

Commit

Permalink
Merge pull request #50 from dhs-ncats/bugfix/treat_multiple_dmarc_pol…
Browse files Browse the repository at this point in the history
…icy_records_as_an_error

Multiple DMARC records is now treated as an error condition
  • Loading branch information
jsf9k committed Jan 11, 2018
2 parents 447589c + 221b50f commit 4e84705
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion trustymail/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from __future__ import unicode_literals, absolute_import, print_function

__version__ = '0.5.1-dev'
__version__ = '0.5.2-dev'
16 changes: 13 additions & 3 deletions trustymail/trustymail.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,16 @@ def dmarc_scan(resolver, domain):
dmarc_domain = '_dmarc.%s' % domain.domain_name
# Use TCP, since we care about the content and correctness of the
# records more than whether their records fit in a single UDP packet.
for record in resolver.query(dmarc_domain, 'TXT', tcp=True):
records = resolver.query(dmarc_domain, 'TXT', tcp=True)

# Treat multiple DMARC records as an error, in accordance with the RFC
# (https://tools.ietf.org/html/rfc7489#section-6.6.3)
if len(records) > 1:
handle_error('[DMARC]', domain, 'Warning: Multiple DMARC records present')
domain.valid_dmarc = False
elif records:
record = records[0]

record_text = record.to_text().strip('"')

# Ensure the record is a DMARC record. Some domains that
Expand All @@ -358,8 +367,9 @@ def dmarc_scan(resolver, domain):
# Remove excess whitespace
record_text = record_text.strip()

# DMARC records follow a specific outline as to how they are defined - tag:value
# We can split this up into a easily manipulatable
# DMARC records follow a specific outline as to how they are
# defined - tag:value We can split this up into a easily
# manipulatable dictionary
tag_dict = {}
for options in record_text.split(';'):
if '=' not in options:
Expand Down

0 comments on commit 4e84705

Please sign in to comment.