Bugzilla – Attachment 181920 Details for
Bug 39789
Add ability to specify an alternative header to X-Forwarded-For for finding the real IP address
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 39789: Add ability to specify an alternative header to X-Forwarded-For for finding the real ip address
Bug-39789-Add-ability-to-specify-an-alternative-he.patch (text/plain), 2.95 KB, created by
Kyle M Hall (khall)
on 2025-05-05 12:37:38 UTC
(
hide
)
Description:
Bug 39789: Add ability to specify an alternative header to X-Forwarded-For for finding the real ip address
Filename:
MIME Type:
Creator:
Kyle M Hall (khall)
Created:
2025-05-05 12:37:38 UTC
Size:
2.95 KB
patch
obsolete
>From 8dd9e49b8979fb03cba4768b28b9046f47b6a52e Mon Sep 17 00:00:00 2001 >From: Kyle M Hall <kyle@bywatersolutions.com> >Date: Wed, 30 Apr 2025 11:16:09 -0400 >Subject: [PATCH] Bug 39789: Add ability to specify an alternative header to > X-Forwarded-For for finding the real ip address > >Some services ( such as CloudFlare ) use alternative heads to X-Forwarded-For. Koha should be able to use a custom header instead of X-Forwarded-For if needed. > >Test Plan: >1) prove t/Koha/Middleware/RealIP.t >--- > C4/Context.pm | 10 ++++++---- > Koha/Middleware/RealIP.pm | 5 +++-- > debian/templates/koha-conf-site.xml.in | 1 + > 3 files changed, 10 insertions(+), 6 deletions(-) > >diff --git a/C4/Context.pm b/C4/Context.pm >index 6296a216f56..95a33ae3e3d 100644 >--- a/C4/Context.pm >+++ b/C4/Context.pm >@@ -880,11 +880,13 @@ variable to be set correctly. > sub set_remote_address { > if ( C4::Context->config('koha_trusted_proxies') ) { > require CGI; >- my $header = CGI->http('HTTP_X_FORWARDED_FOR'); >+ if ( my $reverse_proxy_ip_header = C4::Context->config('reverse_proxy_ip_header') ) { # Updated here >+ my $header = CGI->http($reverse_proxy_ip_header); > >- if ($header) { >- require Koha::Middleware::RealIP; >- $ENV{REMOTE_ADDR} = Koha::Middleware::RealIP::get_real_ip( $ENV{REMOTE_ADDR}, $header ); >+ if ($header) { >+ require Koha::Middleware::RealIP; >+ $ENV{REMOTE_ADDR} = Koha::Middleware::RealIP::get_real_ip( $ENV{REMOTE_ADDR}, $header ); >+ } > } > } > } >diff --git a/Koha/Middleware/RealIP.pm b/Koha/Middleware/RealIP.pm >index 3df5bc0f83b..97394dffe6c 100644 >--- a/Koha/Middleware/RealIP.pm >+++ b/Koha/Middleware/RealIP.pm >@@ -51,11 +51,12 @@ sub call { > my $self = shift; > my $env = shift; > >- if ( $env->{HTTP_X_FORWARDED_FOR} ) { >+ my $reverse_proxy_ip_header = C4::Context->config('reverse_proxy_ip_header'); >+ if ( $reverse_proxy_ip_header && $env->{$reverse_proxy_ip_header} ) { > my @trusted_proxy = $self->trusted_proxy ? @{ $self->trusted_proxy } : undef; > > if (@trusted_proxy) { >- my $addr = get_real_ip( $env->{REMOTE_ADDR}, $env->{HTTP_X_FORWARDED_FOR}, \@trusted_proxy ); >+ my $addr = get_real_ip( $env->{REMOTE_ADDR}, $env->{$reverse_proxy_ip_header}, \@trusted_proxy ); > $ENV{REMOTE_ADDR} = $addr; > $env->{REMOTE_ADDR} = $addr; > } >diff --git a/debian/templates/koha-conf-site.xml.in b/debian/templates/koha-conf-site.xml.in >index 1f034a26c54..4b6fc202d10 100644 >--- a/debian/templates/koha-conf-site.xml.in >+++ b/debian/templates/koha-conf-site.xml.in >@@ -343,6 +343,7 @@ __END_SRU_PUBLICSERVER__ > <!-- Configuration for X-Forwarded-For --> > <!-- > <koha_trusted_proxies>1.2.3.4 2.3.4.5 3.4.5.6</koha_trusted_proxies> >+ <reverse_proxy_ip_header>HTTP_X_FORWARDED_FOR</reverse_proxy_ip_header> > --> > > <!-- Elasticsearch Configuration --> >-- >2.39.5 (Apple Git-154)
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 39789
:
181718
|
181720
|
181915
|
181916
|
181917
|
181918
|
181919
|
181920
|
181921
|
182299
|
182300
|
182395
|
182396
|
182397
|
182841
|
182842
|
182843
|
182844
|
182846
|
182847
|
182848
|
182849
|
183215