diff --git a/C4/Auth.pm b/C4/Auth.pm index 582eefc621..17e2cc17f0 100644 --- a/C4/Auth.pm +++ b/C4/Auth.pm @@ -1614,7 +1614,9 @@ Possible return values in C<$status> are: sub check_cookie_auth { my $cookie = shift; my $flagsrequired = shift; + my $params = shift; + my $remote_addr = $params->{remote_addr} || $ENV{REMOTE_ADDR}; my $dbh = C4::Context->dbh; my $timeout = _timeout_syspref(); @@ -1671,7 +1673,7 @@ sub check_cookie_auth { $userid = undef; $sessionID = undef; return ("expired", undef); - } elsif ( C4::Context->preference('SessionRestrictionByIP') && $ip ne $ENV{'REMOTE_ADDR'} ) { + } elsif ( C4::Context->preference('SessionRestrictionByIP') && $ip ne $remote_addr ) { # IP address changed $session->delete(); diff --git a/Koha/REST/V1.pm b/Koha/REST/V1.pm index b692a38334..b16e1e340e 100644 --- a/Koha/REST/V1.pm +++ b/Koha/REST/V1.pm @@ -29,7 +29,9 @@ sub startup { cb => sub { my $c = shift; - my ($status, $sessionID) = check_cookie_auth($c->cookie('CGISESSID')); + # ENV{REMOTE_ADDR} is not set here, we need to read the headers + my $remote_addr = $c->req->headers->header('x-forwarded-for'); + my ($status, $sessionID) = check_cookie_auth($c->cookie('CGISESSID'), undef, { remote_addr => $remote_addr }); if ($status eq "ok") { my $session = get_session($sessionID); my $user = Koha::Patrons->find($session->param('number'));