]> git.99rst.org Git - git.git/commitdiff
gitweb: implement e-mail privacy using RFC 2822 address parsing kontaxis/rfc2822_email_privacy
authorGeorgios Kontaxis <redacted>
Thu, 25 Jun 2026 17:10:50 +0000 (17:10 +0000)
committerGeorgios Kontaxis <redacted>
Thu, 23 Jul 2026 18:35:09 +0000 (18:35 +0000)
Signed-off-by: Georgios Kontaxis <redacted>
gitweb/gitweb.perl
t/lib-gitweb.sh

index fde804593b6ff388774754a24fe1e12d678dc9a4..3cd354d297ee8c47ebf6fa3f67e69f993b1bae34 100755 (executable)
@@ -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/<[^@>]+@[^>]+>/<redacted>/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 = "<redacted>";
+               $line =~ s/\G(<[^>]+>)/$redaction/;
+
+               pos $line = $match_offset + length($redaction);
+       }
        return $line;
 }
 
index a6e3dd11b3552a477c84c974db29d902fd87183f..a5b4efb9b4ee0ed7c3cf3020e6234e8fe16ae888 100644 (file)
@@ -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
git clone https://git.99rst.org/PROJECT