From: Georgios Kontaxis Date: Thu, 25 Jun 2026 17:10:50 +0000 (+0000) Subject: gitweb: implement e-mail privacy using RFC 2822 address parsing X-Git-Url: http://git.99rst.org/?a=commitdiff_plain;h=refs%2Fheads%2Fkontaxis%2Frfc2822_email_privacy;p=git.git gitweb: implement e-mail privacy using RFC 2822 address parsing Signed-off-by: Georgios Kontaxis --- diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index fde804593b..3cd354d297 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -21,6 +21,7 @@ use File::Basename qw(basename); use Time::HiRes qw(gettimeofday tv_interval); use Digest::MD5 qw(md5_hex); +use Git::LoadCPAN::Mail::Address; binmode STDOUT, ':utf8'; @@ -3460,10 +3461,30 @@ sub parse_date { return %date; } +sub is_mailaddr { + my @addrs = Mail::Address->parse(shift); + if (!@addrs || !$addrs[0]->host || !$addrs[0]->user) { + return 0; + } + return 1; +} + sub hide_mailaddrs_if_private { my $line = shift; return $line unless gitweb_check_feature('email-privacy'); - $line =~ s/<[^@>]+@[^>]+>//g; + while ($line =~ m/(<[^>]+>)/g) { + my $match = $1; + if (!is_mailaddr($match)) { + next; + } + my $match_offset = pos($line) - length($match); + pos $line = $match_offset; + + my $redaction = ""; + $line =~ s/\G(<[^>]+>)/$redaction/; + + pos $line = $match_offset + length($redaction); + } return $line; } diff --git a/t/lib-gitweb.sh b/t/lib-gitweb.sh index a6e3dd11b3..a5b4efb9b4 100644 --- a/t/lib-gitweb.sh +++ b/t/lib-gitweb.sh @@ -67,6 +67,9 @@ gitweb_run () { GITWEB_CONFIG=$(pwd)/gitweb_config.perl export GITWEB_CONFIG + PERL5LIB="$GIT_BUILD_DIR/perl:$GIT_BUILD_DIR/perl/FromCPAN" + export PERL5LIB + # some of git commands write to STDERR on error, but this is not # written to web server logs, so we are not interested in that: # we are interested only in properly formatted errors/warnings