Skip to content

Commit

Permalink
UnrelatedTXTRecordFoundAtDMARC is actually raised when rua/ruf destin…
Browse files Browse the repository at this point in the history
…ation doesn't designate the source domain (domainaware#141)

* UnrelatedTXTRecordFoundAtDMARC contains target info

* .

* .

* .
  • Loading branch information
kazet authored Aug 1, 2024
1 parent cd25ce5 commit 4ec20ee
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions checkdmarc/dmarc.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,8 @@ def _query_dmarc_record(domain: str, nameservers: list[str] = None,
raise UnrelatedTXTRecordFoundAtDMARC(
"Unrelated TXT records were discovered. These should be "
"removed, as some receivers may not expect to find "
f"unrelated TXT records at {target}\n\n{ur_str}")
f"unrelated TXT records at {target}\n\n{ur_str}",
data={"target": target})
if len(dmarc_records) == 1:
dmarc_record = dmarc_records[0]

Expand Down Expand Up @@ -663,7 +664,8 @@ def check_wildcard_dmarc_report_authorization(
"Unrelated TXT records were discovered. "
"These should be removed, as some "
"receivers may not expect to find unrelated TXT records "
f"at {wildcard_target}\n\n{ur_str}")
f"at {wildcard_target}\n\n{ur_str}",
data={"target": wildcard_target})

if dmarc_record_count < 1:
return False
Expand All @@ -678,10 +680,11 @@ def verify_dmarc_report_destination(source_domain: str,
nameservers: list[str] = None,
ignore_unrelated_records: bool = False,
resolver: dns.resolver.Resolver = None,
timeout: float = 2.0) -> bool:
timeout: float = 2.0) -> None:
"""
Checks if the report destination accepts reports for the source domain
per RFC 7489, section 7.1
per RFC 7489, section 7.1. Raises
`checkdmarc.dmarc.UnverifiedDMARCURIDestination` if it doesn't accept.
Args:
source_domain (str): The source domain
Expand All @@ -692,10 +695,6 @@ def verify_dmarc_report_destination(source_domain: str,
requests
timeout (float): number of seconds to wait for an answer from DNS
Returns:
bool: Indicates if the report domain accepts reports from the given
domain
Raises:
:exc:`checkdmarc.dmarc.UnverifiedDMARCURIDestination`
:exc:`checkdmarc.dmarc.UnrelatedTXTRecordFound`
Expand All @@ -710,7 +709,7 @@ def verify_dmarc_report_destination(source_domain: str,
nameservers=nameservers,
ignore_unrelated_records=ignore_unrelated_records,
resolver=resolver):
return True
return
target = f"{source_domain}._report._dmarc.{destination_domain}"
message = f"{destination_domain} does not indicate that it accepts " \
f"DMARC reports about {source_domain} - " \
Expand All @@ -736,15 +735,13 @@ def verify_dmarc_report_destination(source_domain: str,
"Unrelated TXT records were discovered. "
"These should be removed, as some "
"receivers may not expect to find unrelated TXT records "
f"at {target}\n\n{ur_str}")
f"at {target}\n\n{ur_str}", data={"target": target})

if dmarc_record_count < 1:
return False
raise UnverifiedDMARCURIDestination(message)
except Exception:
raise UnverifiedDMARCURIDestination(message)

return True


def parse_dmarc_record(
record: str, domain: str, parked: bool = False,
Expand Down

0 comments on commit 4ec20ee

Please sign in to comment.