From: Dylan Hardison Date: Sun, 21 Jun 2020 15:20:13 +0000 (-0400) Subject: ensure Bugzilla::Util::remote_ip always works X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=536d538a0799ad4a8659f2e368edfc3040ae34c0;p=thirdparty%2Fbugzilla.git ensure Bugzilla::Util::remote_ip always works --- diff --git a/Bugzilla/App/Plugin/Glue.pm b/Bugzilla/App/Plugin/Glue.pm index f17ff7f0e..849aa21c1 100644 --- a/Bugzilla/App/Plugin/Glue.pm +++ b/Bugzilla/App/Plugin/Glue.pm @@ -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->(); } ); diff --git a/Bugzilla/Util.pm b/Bugzilla/Util.pm index dad6d3df2..0cd4bd6bd 100644 --- a/Bugzilla/Util.pm +++ b/Bugzilla/Util.pm @@ -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 {