From b80315e2384a92e7a7ea8c3a6d4b38957851061b Mon Sep 17 00:00:00 2001 From: Stephen Muth Date: Sat, 8 Jul 2017 00:01:03 +0000 Subject: [PATCH] Respect HTTP_X_FORWARDED_HOST alongside _PORT and _PROTO Fixes #879 --- application/HttpUtils.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/application/HttpUtils.php b/application/HttpUtils.php index a81f9056..88a1efdb 100644 --- a/application/HttpUtils.php +++ b/application/HttpUtils.php @@ -311,7 +311,19 @@ function server_url($server) } } - return $scheme.'://'.$server['SERVER_NAME'].$port; + if (isset($server['HTTP_X_FORWARDED_HOST'])) { + // Keep forwarded host + if (strpos($server['HTTP_X_FORWARDED_HOST'], ',') !== false) { + $hosts = explode(',', $server['HTTP_X_FORWARDED_HOST']); + $host = trim($hosts[0]); + } else { + $host = $server['HTTP_X_FORWARDED_HOST']; + } + } else { + $host = $server['SERVER_NAME']; + } + + return $scheme.'://'.$host.$port; } // SSL detection -- 2.41.0