diff options
author | Dylan William Hardison <dylan@hardison.net> | 2018-04-05 03:24:29 +0200 |
---|---|---|
committer | Dylan William Hardison <dylan@hardison.net> | 2018-06-28 22:41:54 +0200 |
commit | e680057dd24ea4290096f4420bdd5c354acea024 (patch) | |
tree | e4aef0eb7755dc8b784901c83eee23f6c13b8638 /Bugzilla/Util.pm | |
parent | ed6d5cdaaeac6422e5933e4e8138b481e35ab4f3 (diff) | |
download | bugzilla-e680057dd24ea4290096f4420bdd5c354acea024.tar.gz bugzilla-e680057dd24ea4290096f4420bdd5c354acea024.tar.xz |
support cgi->http(), remote_ip(), and fix sanity tests
Diffstat (limited to 'Bugzilla/Util.pm')
-rw-r--r-- | Bugzilla/Util.pm | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/Bugzilla/Util.pm b/Bugzilla/Util.pm index a1316c7ef..206c0aa3f 100644 --- a/Bugzilla/Util.pm +++ b/Bugzilla/Util.pm @@ -321,21 +321,26 @@ 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 (Bugzilla->usage_mode == USAGE_MODE_MOJO) { + return Bugzilla->cgi->controller->tx->remote_address; + } + else { + 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; + } } + return $remote_ip; } - return $remote_ip; } sub validate_ip { |