Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Item14181: Detect Proxy host forwarding in bootstrap.
  • Loading branch information
gac410 committed Sep 9, 2016
1 parent 2c7bfaa commit 4fe8fef
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
15 changes: 13 additions & 2 deletions core/lib/Foswiki/Configure/Bootstrap.pm
Expand Up @@ -433,8 +433,19 @@ sub bootstrapWebSettings {

my $protocol = $ENV{HTTPS} ? 'https' : 'http';

# Figure out the DefaultUrlHost
if ( $ENV{HTTP_HOST} ) {
# Figure out the DefaultUrlHost - First check if there is a proxy forwarding requests
# SMELL: This doesn't detect use of HTTPS vs HTTP on the original request. It also
# fails to account for multiple proxies where the forwarded_host is a list of proxies.
if ( $ENV{HTTP_X_FORWARDED_HOST} ) {
$Foswiki::cfg{DefaultUrlHost} =
"$protocol://" . $ENV{HTTP_X_FORWARDED_HOST};
print STDERR "AUTOCONFIG: Set DefaultUrlHost "
. $Foswiki::cfg{DefaultUrlHost}
. " from HTTP_X_FORWARDED_HOST "
. $ENV{HTTP_X_FORWARDED_HOST} . " \n"
if (TRAUTO);
}
elsif ( $ENV{HTTP_HOST} ) {
$Foswiki::cfg{DefaultUrlHost} = "$protocol://$ENV{HTTP_HOST}";
print STDERR
"AUTOCONFIG: Set DefaultUrlHost $Foswiki::cfg{DefaultUrlHost} from HTTP_HOST $ENV{HTTP_HOST} \n"
Expand Down
3 changes: 3 additions & 0 deletions core/lib/Foswiki/Macros/SERVERINFORMATION.pm
Expand Up @@ -75,6 +75,9 @@ DONE
# HTTP headers & SSL data
grep( /^(?:HTTP|SSL)_/, keys %ENV ),

# Custom X_ headers (used in proxies, etc.)
grep( /^X_/, keys %ENV ),

# Other
qw/PATH MOD_PERL MOD_PERL_API_VERSION/,
);
Expand Down

0 comments on commit 4fe8fef

Please sign in to comment.