Skip to content
Browse files

[#25161833] (more) Clean up IP address parsing

There are some proxies which insert a non-IP value into
the HTTP_X_FORWARDED_FOR header (e.g. "unknown") to
protect privacy or who knows why. This would bunge up
Koha's IP detection. This patch looks for something that
looks like a good address, then if all else fails it
resorts to reporting that the client is not in any branch.
  • Loading branch information...
1 parent e644454 commit 4c1129ddbe916984d89f8557548f371b6d103f4d @ctfliblime ctfliblime committed Feb 18, 2012
Showing with 3 additions and 1 deletion.
  1. +3 −1 lib/C4/Branch.pm
View
4 lib/C4/Branch.pm
@@ -19,6 +19,7 @@ package C4::Branch;
use strict;
use warnings;
use Carp;
+use List::Util qw(first);
use List::MoreUtils qw(uniq);
use Net::IP;
@@ -611,8 +612,9 @@ sub GetBranchByIp {
my $raw = shift
// $ENV{HTTP_X_FORWARDED_FOR}
// $ENV{REMOTE_ADDR};
- $raw =~ s/([0-9.]+).*/$1/;
+ $raw = first {/^[0-9]/} split /[^0-9.]+/, $raw;
my $client_ip = Net::IP->new($raw);
+ return undef unless $client_ip;
for my $branch (values %{GetBranches()}) {
next unless $branch->{branchip};

0 comments on commit 4c1129d

Please sign in to comment.
Something went wrong with that request. Please try again.