Closed sorbits closed 4 years ago
I am using F3 v3.7.2, PHP7.4-fpm, Caddy v2.1.1 and Ubuntu 20.04.
Caddy sets SERVER_PORT to an empty string which is handled correctly by F3 when setting up REALM, here the code is as follows:
SERVER_PORT
REALM
($port && !in_array($port,[80,443])?(':'.$port):'')
But it fails in Base::reroute where the code is:
Base::reroute
$port=$this->hive['PORT']; $port=in_array($port,[80,443])?'':(':'.$port);
I propose never setting PORT to an empty string with the following patch:
PORT
--- base.php (old version) +++ base.php (new version) @@ -2433,9 +2433,9 @@ 'samesite'=>'Lax', ]; $port=80; - if (isset($headers['X-Forwarded-Port'])) + if (!empty($headers['X-Forwarded-Port'])) $port=$headers['X-Forwarded-Port']; - elseif (isset($_SERVER['SERVER_PORT'])) + elseif (!empty($_SERVER['SERVER_PORT'])) $port=$_SERVER['SERVER_PORT']; // Default configuration $this->hive+=[ @@ -2496,7 +2496,7 @@ 'QUIET'=>FALSE, 'RAW'=>FALSE, 'REALM'=>$scheme.'://'.$_SERVER['SERVER_NAME']. - ($port && !in_array($port,[80,443])?(':'.$port):''). + (!in_array($port,[80,443])?(':'.$port):''). $_SERVER['REQUEST_URI'], 'RESPONSE'=>'', 'ROOT'=>$_SERVER['DOCUMENT_ROOT'],
For consistency we also check X-Forwarded-Port with !empty and remove the null check for $port when setting up REALM (to make the code consistent with Base::reroute).
X-Forwarded-Port
!empty
$port
Hi. Sounds good. Do you want to create a pull request for fatfree-core?
I am using F3 v3.7.2, PHP7.4-fpm, Caddy v2.1.1 and Ubuntu 20.04.
Caddy sets
SERVER_PORT
to an empty string which is handled correctly by F3 when setting upREALM
, here the code is as follows:But it fails in
Base::reroute
where the code is:I propose never setting
PORT
to an empty string with the following patch:For consistency we also check
X-Forwarded-Port
with!empty
and remove the null check for$port
when setting upREALM
(to make the code consistent withBase::reroute
).