]> git.immae.eu Git - github/shaarli/Shaarli.git/commitdiff
Respect HTTP_X_FORWARDED_HOST
authorStephen Muth <smuth4@gmail.com>
Sat, 8 Jul 2017 00:01:03 +0000 (00:01 +0000)
committerStephen Muth <smuth4@gmail.com>
Sat, 8 Jul 2017 00:01:03 +0000 (00:01 +0000)
alongside _PORT and _PROTO
Fixes #879

application/HttpUtils.php

index a81f90565fb3b79349981cadb049de3a2fe2d6aa..88a1efdb86382646648d9a26a2cbeab022f7ecdf 100644 (file)
@@ -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