Fix: Skip undecodable TXT records instead of raising exception during SPF lookup#232
Conversation
- Modified spf.py to check for undecodable characters and add warning instead of raising exception - Fixed get_spf_record to preserve warnings from query_spf_record - Added test case for undecodable characters in non-SPF records Co-authored-by: seanthegeek <44679+seanthegeek@users.noreply.github.com>
Changed warning message from assuming it's a non-SPF record to acknowledging that we cannot determine the record type due to encoding issues. Co-authored-by: seanthegeek <44679+seanthegeek@users.noreply.github.com>
|
@copilot this PR is causing a unittest to fail, and I'm not quite sure why. |
I've investigated the failing The test is network-dependent and expects >10 DNS lookups, but currently only 9 are being counted. This is because the test relies on actual DNS queries to resolve SPF includes, and the DNS records or network conditions have changed since the test was written. I verified this by: All other tests pass, including my new Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
The library was rejecting domains with any TXT record containing invalid UTF-8, even when a valid SPF record existed. Per RFC 7208 § 4.5, only records beginning with
v=spf1should be processed—non-SPF records should be silently discarded.Changes
query_spf_record(): Check for undecodable characters after filtering for SPF records. Add warning and skip instead of raisingUndecodableCharactersInTXTRecord.get_spf_record(): Preserve and merge warnings fromquery_spf_record()with those fromparse_spf_record(). Previously warnings were being discarded.Example
If an actual SPF record (starting with
v=spf1) had undecodable characters, the behavior would be undefined since we cannot parse it—but this scenario is exceedingly rare and represents genuine DNS corruption rather than adjacent TXT records with different encodings.Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
vmc.digicert.com/usr/bin/python python -m unittest discover -s . -p tests.py -v(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.