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

remove empty record structure in order to stringify it correctly #24

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
40 changes: 33 additions & 7 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,27 +1,53 @@
{{$NEXT}}

3.20240923 2024-09-23 Australia/Melbourne
- Fix issue where certain DNS results would cause an exception to be thrown

3.20240827 2024-08-27 Australia/Melbourne

** Thanks to Giovanni <[email protected]> for the changes in this release.

- Do not try to parse an IPv4 address unnecessarily

- Import RFC7208 Tests

- referencing the same TXT record through multiple CNAME aliases is not permitted
by RFC7208

- Make it clear that BlackMagic module is not available

- Fix checks for IPv4-mapped IPv6 connections

- Cache DNS results

- Misc dzil/build/ci improvements

- SPF explanation text is restricted to 7-bit ascii

3.20240617 2024-06-17 Australia/Melbourne

- Update INSTALL file for Dist::Zilla changes
Thanks to Giovanni <[email protected]>

- Fix memory leak in Mail::SPF::Server when cacheing a Mail::SPF::MacroString
Thanks to Giovanni <[email protected]> and Felipe Gasper

- When mfrom is empty, create a synthetic mfrom (postmaster@helo) and check
that identity using the mfrom scope as specified in RFC7208
Thanks to Giovanni <[email protected]>

- Fix missing declare in Mail::SPF::Server
Thanks to Giovanni <[email protected]>

- require Mail::SPF::Mech when needed
Thanks to Giovanni <[email protected]>

- correctly handle empty labels
Thanks to Giovanni <[email protected]>

- use "try" instead of "eval"
Thanks to Giovanni <[email protected]>

- error out if the lookup fails
Thanks to Giovanni <[email protected]>

Expand Down
17 changes: 8 additions & 9 deletions lib/Mail/SPF/Server.pm
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,8 @@ sub process {
}
catch Mail::SPF::ENoAcceptableRecord with {
if((not defined $request->{record}->{terms}[0]->{domain_spec}->{text}) or ($request->{record}->{terms}[0]->{domain_spec}->{text} !~ /\.\./)) {
# remove empty record structure in order to stringify it correctly
undef $request->{record};
$result = $self->result_class('none' )->new($self, $request, shift->text);
} else {
$result = $self->result_class('permerror')->new($self, $request, shift->text);
Expand Down Expand Up @@ -582,15 +584,12 @@ sub dns_lookup {

# Throw DNS exception unless an answer packet with RCODE 0 or 3 (NXDOMAIN)
# was received (thereby treating NXDOMAIN as an acceptable but empty answer packet):
defined $self->dns_resolver->errorstring and $self->dns_resolver->errorstring !~ /^(timeout|query timed out)$/
or throw Mail::SPF::EDNSTimeout(
"Time-out on DNS '$rr_type' lookup of '$domain'");
defined($packet)
or throw Mail::SPF::EDNSError(
"Unknown error on DNS '$rr_type' lookup of '$domain'");
$packet->header->rcode =~ /^(NOERROR|NXDOMAIN)$/
or throw Mail::SPF::EDNSError(
"'" . $packet->header->rcode . "' error on DNS '$rr_type' lookup of '$domain'");
throw Mail::SPF::EDNSTimeout("Time-out on DNS '$rr_type' lookup of '$domain'")
if defined $self->dns_resolver->errorstring && $self->dns_resolver->errorstring =~ /^(timeout|query timed out)$/;
throw Mail::SPF::EDNSError("Unknown error on DNS '$rr_type' lookup of '$domain'")
unless defined $packet;
throw Mail::SPF::EDNSError("'" . $packet->header->rcode . "' error on DNS '$rr_type' lookup of '$domain'")
unless $packet->header->rcode =~ /^(NOERROR|NXDOMAIN)$/;

return $packet;
}
Expand Down
4 changes: 3 additions & 1 deletion lib/Mail/SPF/Util.pm
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,9 @@ sub ip_address_reverse {
or throw Mail::SPF::EInvalidOptionValue('NetAddr::IP IPv4 or IPv6 address expected');
try {
# Treat IPv4-mapped IPv6 addresses as IPv4 addresses:
$ip_address = $self->ipv6_address_to_ipv4($ip_address);
if($ip_address->version == 6) {
$ip_address = $self->ipv6_address_to_ipv4($ip_address);
}
}
catch Mail::SPF::EInvalidOptionValue with {};
# ...deliberately ignoring conversion errors.
Expand Down
Loading