Skip to content

Commit

Permalink
Check IDN domains against the PSL correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
marcbradshaw committed Jun 25, 2015
1 parent b7962a6 commit 1ba5b44
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/Mail/DMARC/Base.pm
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use File::ShareDir;
use HTTP::Tiny;
use IO::File;
use Net::DNS::Resolver;
use Net::IDN::Encode qw/domain_to_unicode/;
use Net::IP;
use Regexp::Common 2013031301 qw /net/;
use Socket;
Expand Down Expand Up @@ -97,13 +98,15 @@ sub any_inet_pton {
my $file = $self->find_psl_file();
$public_suffixes_stamp = ( stat( $file ) )[9];

my $fh = IO::File->new( $file, 'r' )
open my $fh, '<:encoding(UTF-8)', $file
or croak "unable to open $file for read: $!\n";
# load PSL into hash for fast lookups, esp. for long running daemons
my @data = <$fh>;
close $fh;
my %psl = map { $_ => 1 }
grep { $_ !~ /^[\/\s]/ } # weed out comments & whitespace
map { chomp($_); $_ } # remove line endings
<$fh>;
@data;
return $public_suffixes = \%psl;
}

Expand All @@ -128,6 +131,8 @@ sub is_public_suffix {

my $public_suffixes = $self->get_public_suffix_list();

$zone = domain_to_unicode( $zone ) if $zone =~ /xn--/;

return 1 if $public_suffixes->{$zone};

my @labels = split /\./, $zone;
Expand Down
17 changes: 17 additions & 0 deletions t/00.Dmarc.t
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,27 @@ test_dkim();
test_zulu_time();
test_report_window();
test_interval_limits();
test_public_suffix_list();

done_testing();
exit;

sub test_public_suffix_list {

my $data = {
'com' => 1,
'examplebogusdomainname' => 0,
'xn--55qx5d.cn' => 1,
'xn--zfr164b' => 1,
};

foreach my $domain ( keys %$data ) {
my $result = $dmarc->is_public_suffix( $domain );
is( $result, $data->{ $domain }, "Public Suffix: $domain" );
}

}

sub test_zulu_time {

my $data = [
Expand Down

0 comments on commit 1ba5b44

Please sign in to comment.