]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
ensure Bugzilla::Util::remote_ip always works
authorDylan Hardison <dylan@hardison.net>
Sun, 21 Jun 2020 15:20:13 +0000 (11:20 -0400)
committerDylan Hardison <dylan@hardison.net>
Sun, 21 Jun 2020 15:23:35 +0000 (11:23 -0400)
Bugzilla/App/Plugin/Glue.pm
Bugzilla/Util.pm

index f17ff7f0ec41232423d4d4c157772d48bd09d99a..849aa21c1cadd2266082d61195f5132f13c113ae 100644 (file)
@@ -55,6 +55,11 @@ sub register {
       # We also need to clear CGI's globals.
       CGI::initialize_globals();
       Bugzilla->usage_mode(USAGE_MODE_MOJO);
+
+      # This is used by Bugzilla::Util::remote_ip().
+      state $better_xff = Bugzilla->has_feature('better_xff');
+      Bugzilla->request_cache->{remote_ip} = $better_xff ? $c->forwarded_for : $c->tx->remote_address;
+
       $next->();
     }
   );
index dad6d3df2324474b46b92ad08a641e3ce0617832..0cd4bd6bd91fc7f4249e82ed32737899f9e4b553 100644 (file)
@@ -329,15 +329,7 @@ sub do_ssl_redirect_if_required {
 
 # Returns the real remote address of the client,
 sub remote_ip {
-  if (($ENV{SERVER_SOFTWARE} // '') eq 'Bugzilla::App::CGI') {
-    my $c = $Bugzilla::App::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 Bugzilla->request_cache->{remote_ip};
 }
 
 sub validate_ip {