]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 1501888 - Implement Bugzilla::Util::remote_ip() in terms of Mojolicious API
authorDylan William Hardison <dylan@hardison.net>
Thu, 25 Oct 2018 19:33:49 +0000 (15:33 -0400)
committerGitHub <noreply@github.com>
Thu, 25 Oct 2018 19:33:49 +0000 (15:33 -0400)
Bugzilla/Quantum.pm
Bugzilla/Util.pm
Makefile.PL

index 927729614e6d736275671938ae123e8281e12e95..84618a71b94859bc97998a5d893822403bacd6aa 100644 (file)
@@ -42,6 +42,7 @@ sub startup {
     unless $ENV{BUGZILLA_DISABLE_HOSTAGE};
   $self->plugin('Bugzilla::Quantum::Plugin::SizeLimit')
     unless $ENV{BUGZILLA_DISABLE_SIZELIMIT};
+  $self->plugin('ForwardedFor') if Bugzilla->has_feature('better_xff');
   $self->plugin('Bugzilla::Quantum::Plugin::BlockIP');
   $self->plugin('Bugzilla::Quantum::Plugin::Helpers');
 
index aa524b263145a35f910c72aa646bea4e4f6b72d9..780cd45d4210e6294d8983ffdab207c577d8d947 100644 (file)
@@ -323,21 +323,16 @@ sub do_ssl_redirect_if_required {
 
 # Returns the real remote address of the client,
 sub remote_ip {
-    my $remote_ip       = $ENV{'REMOTE_ADDR'} || '127.0.0.1';
-    my @proxies         = split(/[\s,]+/, Bugzilla->localconfig->{inbound_proxies});
-    my @x_forwarded_for = split(/[\s,]+/, $ENV{HTTP_X_FORWARDED_FOR} // '');
-
-    return $remote_ip unless @x_forwarded_for;
-    return $x_forwarded_for[0] if @proxies && $proxies[0] eq '*';
-    return $remote_ip if none { $_ eq $remote_ip } @proxies;
-
-    foreach my $ip (reverse @x_forwarded_for) {
-        if (none { $_ eq $ip } @proxies) {
-            # Keep the original IP address if the remote IP is invalid.
-            return validate_ip($ip) || $remote_ip;
-        }
+    if ($ENV{SERVER_SOFTWARE} eq 'Bugzilla::Quantum::CGI') {
+        my $c = $Bugzilla::Quantum::CGI::C
+            or LOGDIE("Cannot find controller!");
+        state $better_xff = Bugzilla->has_feature('better_xff');
+        return $better_xff ? $c->forwarded_for : $c->tx->remote_address;
+    }
+    else {
+        WARN("remote_ip() called outside CGI controller!");
+        return "";
     }
-    return $remote_ip;
 }
 
 sub validate_ip {
index b73080bea6c746bba6976b6435256365fe4c4d31..156ef83d3a84c2df04ec170121efb57305249a34 100755 (executable)
@@ -129,6 +129,11 @@ if ($OSNAME eq 'linux' && -f '/etc/debian_version') {
 }
 
 my %optional_features = (
+  better_xff => {
+    description => 'Improved behavior of MOJO_REVERSE_PROXY',
+    prereqs =>
+      {runtime => {requires => {'Mojolicious::Plugin::ForwardedFor' => 0}}}
+  },
   alien_cmark => {
     description => 'Support GitHub-flavored markdown',
     prereqs     => {runtime => {requires => {'Alien::libcmark_gfm' => '3'},},},
@@ -300,7 +305,10 @@ my %optional_features = (
   },
   linux_smaps => {
     description => 'Linux::Smaps::Tiny for limiting memory usage',
-    prereqs     => {runtime => {requires => {'Linux::Smaps::Tiny' => '0', 'BSD::Resource' => 0}}},
+    prereqs     => {
+      runtime =>
+        {requires => {'Linux::Smaps::Tiny' => '0', 'BSD::Resource' => 0}}
+    },
   },
   linux_pdeath => {
     description => 'Linux::Pdeathsig for a good parent/child relationships',