Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing the querying of base domain #132

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions checkdmarc/dmarc.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,8 @@ def _query_dmarc_record(domain: str, nameservers: list[str] = None,
pass
except DMARCRecordStartsWithWhitespace as error:
raise error
except UnrelatedTXTRecordFoundAtDMARC as error:
raise error
except MultipleDMARCRecords as error:
raise error
except Exception as error:
Expand Down Expand Up @@ -490,10 +492,18 @@ def query_dmarc_record(domain: str, nameservers: list[str] = None,
warnings = []
base_domain = get_base_domain(domain)
location = domain.lower()
record = _query_dmarc_record(
domain, nameservers=nameservers,
resolver=resolver, timeout=timeout,
ignore_unrelated_records=ignore_unrelated_records)

try:
record = _query_dmarc_record(
domain, nameservers=nameservers,
resolver=resolver, timeout=timeout,
ignore_unrelated_records=ignore_unrelated_records)
except DMARCRecordNotFound:
# Skip this exception as we want to query the base domain. If we fail
# at that, at the end of this function we will raise another
# DMARCRecordNotFound.
record = None

try:
root_records = query_dns(domain, "TXT",
nameservers=nameservers, resolver=resolver,
Expand All @@ -509,8 +519,12 @@ def query_dmarc_record(domain: str, nameservers: list[str] = None,
pass

if record is None and domain != base_domain:
record = _query_dmarc_record(base_domain, nameservers=nameservers,
resolver=resolver, timeout=timeout)
record = _query_dmarc_record(
base_domain,
nameservers=nameservers,
resolver=resolver,
timeout=timeout,
ignore_unrelated_records=ignore_unrelated_records)
location = base_domain
if record is None:
raise DMARCRecordNotFound(
Expand Down
Loading