From 99edf17b75456d0cada9455913ca3169e2cf821b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?C=C3=B4me=20Chilliet?= <come.chilliet@fusiondirectory.org>
Date: Thu, 6 Aug 2020 15:16:28 +0200
Subject: [PATCH] :ambulance: fix(core) Fix port detection when using a proxy
 and https

issue #6108
---
 include/class_URL.inc | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/include/class_URL.inc b/include/class_URL.inc
index 9788c1820..0ad8c72be 100644
--- a/include/class_URL.inc
+++ b/include/class_URL.inc
@@ -46,15 +46,16 @@ class URL
       $protocol .= 's';
     }
 
-    $port = '80';
     if (!empty($_SERVER['HTTP_X_FORWARDED_HOST'])) {
       $host = $_SERVER['HTTP_X_FORWARDED_HOST'];
-      if (isset($_SERVER['HTTP_X_FORWARDED_PORT'])) {
-        $port = $_SERVER['HTTP_X_FORWARDED_PORT'];
-      }
       if (isset($_SERVER['HTTP_X_FORWARDED_PROTO'])) {
         $protocol = $_SERVER['HTTP_X_FORWARDED_PROTO'];
       }
+      if (isset($_SERVER['HTTP_X_FORWARDED_PORT'])) {
+        $port = $_SERVER['HTTP_X_FORWARDED_PORT'];
+      } else {
+        $port = ($protocol === 'http' ? 80 : 443);
+      }
     } else {
       if (!empty($_SERVER['HTTP_HOST'])) {
         $host = $_SERVER['HTTP_HOST'];
-- 
GitLab