Permalink
Browse files

Item14544: Process X-Forwarded-For header correctly.

Split and use the first entry when mulltiple hosts are listed.
  • Loading branch information...
gac410 committed Dec 8, 2017
1 parent 57c3179 commit 2f4a4774c1085aec784799dbfd9f647fafe33ce4
@@ -128,7 +128,7 @@ sub prepareHeaders {
$req->remoteUser( $this->{r}->user );
if ( $Foswiki::cfg{BehindProxy} ) {
if ( my $source = $req->header('X-Forwarded-For') ) {
my $ip = ( split /[, ]+/, $source )[-1];
my $ip = ( split /[, ]+/, $source )[0];
$req->remoteAddress($1)
if defined $ip and $ip =~ /^((?:\d{1,3}\.){3}\d{1,3})$/;
}
@@ -461,8 +461,9 @@ sub bootstrapWebSettings {
print STDERR "AUTOCONFIG: Detected HTTPS\n";
}
$Foswiki::cfg{DefaultUrlHost} =
"$protocol://" . $ENV{HTTP_X_FORWARDED_HOST};
my $vh = ( split /[, ]+/, $ENV{HTTP_X_FORWARDED_HOST} )[0];
$Foswiki::cfg{DefaultUrlHost} = "$protocol://" . $vh;
$Foswiki::cfg{ForceDefaultUrlHost} =
1; # Force the URL host when behind a proxy
@@ -299,6 +299,7 @@ sub url {
}
else {
my $vh = $this->header('X-Forwarded-Host') || $this->header('Host');
$vh = ( split /[, ]+/, $vh )[0];
$url =
$vh
? $this->protocol . '://' . $vh

0 comments on commit 2f4a477

Please sign in to comment.