Commit d2f4fc21 authored by IKEDA Soji's avatar IKEDA Soji
Browse files

Some clarification: Use canonic_email() to canonicalize email addresses

parent 1ced6143
...@@ -1348,11 +1348,9 @@ while ($query = Sympa::WWW::FastCGI->new) { ...@@ -1348,11 +1348,9 @@ while ($query = Sympa::WWW::FastCGI->new) {
if (defined $net_id) { # the ticket is valid net-id if (defined $net_id) { # the ticket is valid net-id
$log->syslog('notice', 'Login CAS OK server netid=%s', $log->syslog('notice', 'Login CAS OK server netid=%s',
$net_id); $net_id);
$param->{'user'}{'email'} = lc( $param->{'user'}{'email'} =
Sympa::WWW::Auth::get_email_by_net_id( Sympa::WWW::Auth::get_email_by_net_id($robot,
$robot, $cas_id, {'uid' => $net_id} $cas_id, {'uid' => $net_id});
)
);
$session->{'auth'} = 'cas'; $session->{'auth'} = 'cas';
$session->{'email'} = $param->{user}{email}; $session->{'email'} = $param->{user}{email};
   
...@@ -2070,8 +2068,8 @@ sub get_parameters { ...@@ -2070,8 +2068,8 @@ sub get_parameters {
# mod_ssl sets SSL_PROTOCOL; Apache-SSL sets SSL_PROTOCOL_VERSION. # mod_ssl sets SSL_PROTOCOL; Apache-SSL sets SSL_PROTOCOL_VERSION.
$param->{'use_ssl'} = ($ENV{HTTPS} && $ENV{HTTPS} eq 'on'); $param->{'use_ssl'} = ($ENV{HTTPS} && $ENV{HTTPS} eq 'on');
   
## Lowercase email addresses # Canonicalize email addresses.
$in{'email'} = lc($in{'email'}); $in{'email'} = Sympa::Tools::Text::canonic_email($in{'email'});
   
## Don't get multiple listnames ## Don't get multiple listnames
if ($in{'list'}) { if ($in{'list'}) {
...@@ -3420,7 +3418,8 @@ sub do_sso_login { ...@@ -3420,7 +3418,8 @@ sub do_sso_login {
{'email_http_header'} && !$email_is_trusted) { {'email_http_header'} && !$email_is_trusted) {
my @email_list = split( my @email_list = split(
/$Conf::Conf{'auth_services'}{$robot}[$sso_id]{'http_header_value_separator'}/, /$Conf::Conf{'auth_services'}{$robot}[$sso_id]{'http_header_value_separator'}/,
lc( $ENV{ Sympa::Tools::Text::canonic_email(
$ENV{
$Conf::Conf{'auth_services'}{$robot}[$sso_id] $Conf::Conf{'auth_services'}{$robot}[$sso_id]
{'email_http_header'} {'email_http_header'}
} }
...@@ -3588,7 +3587,8 @@ sub do_sso_login { ...@@ -3588,7 +3587,8 @@ sub do_sso_login {
my @email_list = split( my @email_list = split(
$Conf::Conf{'auth_services'}{$robot}[$sso_id] $Conf::Conf{'auth_services'}{$robot}[$sso_id]
{'http_header_value_separator'}, {'http_header_value_separator'},
lc( $ENV{ Sympa::Tools::Text::canonic_email(
$ENV{
$Conf::Conf{'auth_services'}{$robot}[$sso_id] $Conf::Conf{'auth_services'}{$robot}[$sso_id]
{'email_http_header'} {'email_http_header'}
} }
...@@ -5292,12 +5292,11 @@ sub do_set { ...@@ -5292,12 +5292,11 @@ sub do_set {
'update_date' => time 'update_date' => time
}; };
   
## Lower-case new email address # Canonicalize new email address.
$in{'new_email'} = lc($in{'new_email'}); $in{'new_email'} = Sympa::Tools::Text::canonic_email($in{'new_email'});
   
if ($in{'new_email'} and $in{'email'} ne $in{'new_email'}) { if ($in{'new_email'} and $in{'email'} ne $in{'new_email'}) {
unless ($in{'new_email'} unless (Sympa::Tools::Text::valid_email($in{'new_email'})) {
and Sympa::Tools::Text::valid_email($in{'new_email'})) {
wwslog('notice', 'Incorrect email %s', $in{'new_email'}); wwslog('notice', 'Incorrect email %s', $in{'new_email'});
Sympa::WWW::Report::reject_report_web('user', 'incorrect_email', Sympa::WWW::Report::reject_report_web('user', 'incorrect_email',
{'email' => $in{'new_email'}}, {'email' => $in{'new_email'}},
...@@ -5587,7 +5586,7 @@ sub do_subscribe { ...@@ -5587,7 +5586,7 @@ sub do_subscribe {
wwslog('notice', "Missing required custom attributes"); wwslog('notice', "Missing required custom attributes");
return 1; return 1;
} }
unless ($email and Sympa::Tools::Text::valid_email($email)) { unless (Sympa::Tools::Text::valid_email($email)) {
return 1; return 1;
} }
   
...@@ -5718,7 +5717,7 @@ sub do_auto_signoff { ...@@ -5718,7 +5717,7 @@ sub do_auto_signoff {
   
my $email = Sympa::Tools::Text::canonic_email($in{'email'}); my $email = Sympa::Tools::Text::canonic_email($in{'email'});
return $default_home return $default_home
unless $email and Sympa::Tools::Text::valid_email($email); unless Sympa::Tools::Text::valid_email($email);
   
$param->{'email'} = $email; $param->{'email'} = $email;
   
...@@ -5784,7 +5783,7 @@ sub do_family_signoff { ...@@ -5784,7 +5783,7 @@ sub do_family_signoff {
unless $family; unless $family;
my $email = Sympa::Tools::Text::canonic_email($in{'email'}); my $email = Sympa::Tools::Text::canonic_email($in{'email'});
return $default_home return $default_home
unless $email and Sympa::Tools::Text::valid_email($email); unless Sympa::Tools::Text::valid_email($email);
   
$param->{'email'} = $email; $param->{'email'} = $email;
$param->{'family'} = $family->{name}; $param->{'family'} = $family->{name};
...@@ -5858,7 +5857,7 @@ sub do_signoff { ...@@ -5858,7 +5857,7 @@ sub do_signoff {
   
$param->{email} = $email; $param->{email} = $email;
   
unless ($email and Sympa::Tools::Text::valid_email($email)) { unless (Sympa::Tools::Text::valid_email($email)) {
return 1; return 1;
} }
   
...@@ -8011,7 +8010,7 @@ sub do_add_frommod { ...@@ -8011,7 +8010,7 @@ sub do_add_frommod {
next; next;
} }
my $email = $message->{sender}; my $email = $message->{sender};
next unless $email and Sympa::Tools::Text::valid_email($email); next unless Sympa::Tools::Text::valid_email($email);
my $fullname = $message->{gecos} my $fullname = $message->{gecos}
if defined $message->{gecos} and $message->{gecos} =~ /\S/; if defined $message->{gecos} and $message->{gecos} =~ /\S/;
   
...@@ -10794,7 +10793,7 @@ sub _notify_deleted_topic { ...@@ -10794,7 +10793,7 @@ sub _notify_deleted_topic {
); );
unless ( unless (
$list->update_list_member( $list->update_list_member(
lc($subscriber->{'email'}), $subscriber->{'email'},
update_date => time, update_date => time,
topics => join(',', @{$topics->{'added'}}) topics => join(',', @{$topics->{'added'}})
) )
...@@ -13641,7 +13640,7 @@ sub do_d_set_owner { ...@@ -13641,7 +13640,7 @@ sub do_d_set_owner {
# The email must look like an email "somebody@somewhere". # The email must look like an email "somebody@somewhere".
my $email = Sympa::Tools::Text::canonic_email($in{'content'}) my $email = Sympa::Tools::Text::canonic_email($in{'content'})
if $in{'content'}; if $in{'content'};
unless ($email and Sympa::Tools::Text::valid_email($email)) { unless (Sympa::Tools::Text::valid_email($email)) {
Sympa::WWW::Report::reject_report_web('user', 'incorrect_email', Sympa::WWW::Report::reject_report_web('user', 'incorrect_email',
{'email' => $in{'content'}}, {'email' => $in{'content'}},
$param->{'action'}, $list); $param->{'action'}, $list);
...@@ -17136,7 +17135,7 @@ sub do_auth { ...@@ -17136,7 +17135,7 @@ sub do_auth {
   
my $default_home = Conf::get_robot_conf($robot, 'default_home'); my $default_home = Conf::get_robot_conf($robot, 'default_home');
return $default_home return $default_home
unless $email and Sympa::Tools::Text::valid_email($email); unless Sympa::Tools::Text::valid_email($email);
   
@{$param}{qw(id heldaction listname email)} = @{$param}{qw(id heldaction listname email)} =
($keyauth, $heldaction, $listname, $email); ($keyauth, $heldaction, $listname, $email);
...@@ -17409,8 +17408,7 @@ sub _add_in_blacklist { ...@@ -17409,8 +17408,7 @@ sub _add_in_blacklist {
my $list = shift; my $list = shift;
   
$log->syslog('info', '(%s, %s, %s)', $entry, $robot, $list->{'name'}); $log->syslog('info', '(%s, %s, %s)', $entry, $robot, $list->{'name'});
$entry = lc($entry); $entry = Sympa::Tools::Text::canonic_email($entry);
chomp $entry;
   
# robot blacklist not yet availible # robot blacklist not yet availible
unless ($list) { unless ($list) {
......
...@@ -669,6 +669,7 @@ sub get_listmasters_email { ...@@ -669,6 +669,7 @@ sub get_listmasters_email {
} }
my @listmasters = my @listmasters =
map { Sympa::Tools::Text::canonic_email($_) }
grep { Sympa::Tools::Text::valid_email($_) } split /\s*,\s*/, grep { Sympa::Tools::Text::valid_email($_) } split /\s*,\s*/,
$listmaster; $listmaster;
# If no valid adresses found, use listmaster of site config. # If no valid adresses found, use listmaster of site config.
...@@ -753,8 +754,8 @@ sub is_listmaster { ...@@ -753,8 +754,8 @@ sub is_listmaster {
my $who = Sympa::Tools::Text::canonic_email(shift); my $who = Sympa::Tools::Text::canonic_email(shift);
return undef unless defined $who; return undef unless defined $who;
return 1 if grep { lc $_ eq $who } Sympa::get_listmasters_email($that); return 1 if grep { $_ eq $who } Sympa::get_listmasters_email($that);
return 1 if grep { lc $_ eq $who } Sympa::get_listmasters_email('*'); return 1 if grep { $_ eq $who } Sympa::get_listmasters_email('*');
return 0; return 0;
} }
......
...@@ -73,10 +73,6 @@ sub _next { ...@@ -73,10 +73,6 @@ sub _next {
next; next;
} }
my ($email, $gecos) = ($1, $2); my ($email, $gecos) = ($1, $2);
unless (Sympa::Tools::Text::valid_email($email)) {
$log->syslog('err', 'Skip badly formed email: "%s"', $email);
next;
}
$gecos =~ s/\s+\z// if defined $gecos; $gecos =~ s/\s+\z// if defined $gecos;
$found++; $found++;
......
...@@ -260,7 +260,8 @@ sub _get_sender_email { ...@@ -260,7 +260,8 @@ sub _get_sender_email {
## Try to get envelope sender ## Try to get envelope sender
if ( $self->{'envelope_sender'} if ( $self->{'envelope_sender'}
and $self->{'envelope_sender'} ne '<>') { and $self->{'envelope_sender'} ne '<>') {
$sender = lc($self->{'envelope_sender'}); $sender = Sympa::Tools::Text::canonic_email(
$self->{'envelope_sender'});
} }
} elsif ($hdr->get($field)) { } elsif ($hdr->get($field)) {
## Try to get message header. ## Try to get message header.
...@@ -271,7 +272,8 @@ sub _get_sender_email { ...@@ -271,7 +272,8 @@ sub _get_sender_email {
my $addr = $hdr->get($field, 0); # get the first one my $addr = $hdr->get($field, 0); # get the first one
my @sender_hdr = Mail::Address->parse($addr); my @sender_hdr = Mail::Address->parse($addr);
if (@sender_hdr and $sender_hdr[0]->address) { if (@sender_hdr and $sender_hdr[0]->address) {
$sender = lc($sender_hdr[0]->address); $sender = Sympa::Tools::Text::canonic_email(
$sender_hdr[0]->address);
my $phrase = $sender_hdr[0]->phrase; my $phrase = $sender_hdr[0]->phrase;
if (defined $phrase and length $phrase) { if (defined $phrase and length $phrase) {
$gecos = MIME::EncWords::decode_mimewords($phrase, $gecos = MIME::EncWords::decode_mimewords($phrase,
...@@ -1294,7 +1296,7 @@ sub check_smime_signature { ...@@ -1294,7 +1296,7 @@ sub check_smime_signature {
## Messages that should not be altered (no footer) ## Messages that should not be altered (no footer)
$self->{'protected'} = 1; $self->{'protected'} = 1;
my $sender = $self->{'sender'}; my $sender = Sympa::Tools::Text::canonic_email($self->{'sender'});
# First step is to check if message signing is OK. # First step is to check if message signing is OK.
my $smime = Crypt::SMIME->new; my $smime = Crypt::SMIME->new;
...@@ -1318,7 +1320,7 @@ sub check_smime_signature { ...@@ -1318,7 +1320,7 @@ sub check_smime_signature {
foreach my $cert (@{$signers || []}) { foreach my $cert (@{$signers || []}) {
my $parsed = Sympa::Tools::SMIME::parse_cert(text => $cert); my $parsed = Sympa::Tools::SMIME::parse_cert(text => $cert);
next unless $parsed; next unless $parsed;
next unless $parsed->{'email'}{lc $sender}; next unless $parsed->{'email'}{$sender};
if ($parsed->{'purpose'}{'sign'} and $parsed->{'purpose'}{'enc'}) { if ($parsed->{'purpose'}{'sign'} and $parsed->{'purpose'}{'enc'}) {
$certs{'both'} = $cert; $certs{'both'} = $cert;
...@@ -1342,8 +1344,8 @@ sub check_smime_signature { ...@@ -1342,8 +1344,8 @@ sub check_smime_signature {
# or a pair of single-purpose. save them, as email@addr if combined, # or a pair of single-purpose. save them, as email@addr if combined,
# or as email@addr@sign / email@addr@enc for split certs. # or as email@addr@sign / email@addr@enc for split certs.
foreach my $c (keys %certs) { foreach my $c (keys %certs) {
my $filename = "$Conf::Conf{ssl_cert_dir}/" my $filename = sprintf '%s/%s', $Conf::Conf{'ssl_cert_dir'},
. Sympa::Tools::Text::escape_chars(lc($sender)); Sympa::Tools::Text::escape_chars($sender);
if ($c ne 'both') { if ($c ne 'both') {
unlink $filename; # just in case there's an old cert left... unlink $filename; # just in case there's an old cert left...
$filename .= "\@$c"; $filename .= "\@$c";
......
...@@ -36,6 +36,7 @@ use Sympa::List; ...@@ -36,6 +36,7 @@ use Sympa::List;
use Sympa::LockedFile; use Sympa::LockedFile;
use Sympa::Log; use Sympa::Log;
use Sympa::Template; use Sympa::Template;
use Sympa::Tools::Text;
use base qw(Sympa::Request::Handler); use base qw(Sympa::Request::Handler);
......
...@@ -31,6 +31,7 @@ use Sympa::DatabaseManager; ...@@ -31,6 +31,7 @@ use Sympa::DatabaseManager;
use Sympa::DataSource; use Sympa::DataSource;
use Sympa::LockedFile; use Sympa::LockedFile;
use Sympa::Log; use Sympa::Log;
use Sympa::Tools::Text;
use base qw(Sympa::Request::Handler); use base qw(Sympa::Request::Handler);
......
...@@ -39,6 +39,7 @@ use Sympa::ListDef; ...@@ -39,6 +39,7 @@ use Sympa::ListDef;
use Sympa::Log; use Sympa::Log;
use Sympa::Tools::Data; use Sympa::Tools::Data;
use Sympa::Tools::File; use Sympa::Tools::File;
use Sympa::Tools::Text;
my $language = Sympa::Language->instance; my $language = Sympa::Language->instance;
my $log = Sympa::Log->instance; my $log = Sympa::Log->instance;
......
...@@ -118,7 +118,7 @@ sub _twist { ...@@ -118,7 +118,7 @@ sub _twist {
# Pick address only. # Pick address only.
my @to = Mail::Address->parse($to); my @to = Mail::Address->parse($to);
if (@to and $to[0] and $to[0]->address) { if (@to and $to[0] and $to[0]->address) {
$to = lc($to[0]->address); $to = Sympa::Tools::Text::canonic_email($to[0]->address);
} else { } else {
undef $to; undef $to;
} }
......
...@@ -30,6 +30,7 @@ use English qw(-no_match_vars); ...@@ -30,6 +30,7 @@ use English qw(-no_match_vars);
use Conf; use Conf;
use Sympa::Log; use Sympa::Log;
use Sympa::Tools::Text;
my $log = Sympa::Log->instance; my $log = Sympa::Log->instance;
...@@ -185,10 +186,10 @@ sub parse_cert { ...@@ -185,10 +186,10 @@ sub parse_cert {
} }
if (%emails) { if (%emails) {
foreach my $email (keys %emails) { foreach my $email (keys %emails) {
$res{email}{lc($email)} = 1; $res{email}{Sympa::Tools::Text::canonic_email($email)} = 1;
} }
} elsif ($x509->email) { } elsif ($x509->email) {
$res{email}{lc($x509->email)} = 1; $res{email}{Sympa::Tools::Text::canonic_email($x509->email)} = 1;
} }
# Check key usage roughy. # Check key usage roughy.
my %purposes = $x509->extensions_by_name->{keyUsage}->hash_bit_string; my %purposes = $x509->extensions_by_name->{keyUsage}->hash_bit_string;
......
...@@ -508,7 +508,8 @@ sub unescape_chars { ...@@ -508,7 +508,8 @@ sub unescape_chars {
sub valid_email { sub valid_email {
my $email = shift; my $email = shift;
return undef unless $email =~ /\A$email_re\z/; return undef
unless defined $email and $email =~ /\A$email_re\z/;
return 1; return 1;
} }
......
...@@ -346,12 +346,13 @@ sub get_email_by_net_id { ...@@ -346,12 +346,13 @@ sub get_email_by_net_id {
$db->disconnect(); $db->disconnect();
## return only the first attribute # Return only the first attribute.
my @results = $mesg->entries; foreach my $result ($mesg->entries) {
foreach my $result (@results) { my $email = $result->get_value($ldap->{'email_attribute'});
return (lc($result->get_value($ldap->{'email_attribute'}))); return undef unless Sympa::Tools::Text::valid_email($email);
return Sympa::Tools::Text::canonic_email($email);
} }
return undef;
} }
# check trusted_application_name et trusted_application_password : return 1 or # check trusted_application_name et trusted_application_password : return 1 or
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment