TemaTres-Vocabulary-Server icon indicating copy to clipboard operation
TemaTres-Vocabulary-Server copied to clipboard

Add option to enforce https

Open T1loc opened this issue 4 years ago • 2 comments

Hello,

Since I use tematres with docker, behind an ingress controller (Nginx Loadbalancer) the function getURLBase is not working as expected because the protocal between my loadbalancer and the docker image is http.

So we have now some mixt-content blocked by browsers.

What do you think about adding an entry into the config.tematres.php ? Like : CFG["https_enforce"] = true | default to false

And then adapt this piece of code :

function getURLbase()
{
        // The line below need to be adapted.
        $s = empty($_SERVER["HTTPS"]) ? '' : ($_SERVER["HTTPS"] == "on") ? "s" : ""; 

	$protocol = substr(strtolower($_SERVER["SERVER_PROTOCOL"]), 0, strpos(strtolower($_SERVER["SERVER_PROTOCOL"]), "/")) . $s;
	$port = ($_SERVER["SERVER_PORT"] == "80") ? "" : (":".$_SERVER["SERVER_PORT"]);
	$uri = $protocol . "://" . $_SERVER['SERVER_NAME'] . $port . $_SERVER['REQUEST_URI'];
	$segments = explode('?', $uri, 2);
	$url = $segments[0];

	$url_base=substr($url,0,strripos($url,"/")+1);

	return $url_base;
}

T1loc avatar May 25 '20 08:05 T1loc

Hi @T1loc :) yes.. it's can be a useful feature. Something like this? $s = empty($_SERVER["HTTPS"]) ? '' : ($_SERVER["HTTPS"] == "on") ? "s" : ""; $s = ($CFG["https_enforce"]) ? $_SERVER["HTTPS"] : $s ;

It's ok?

tematres avatar May 30 '20 14:05 tematres

HI @tematres, I don't think so.

For some use case you have this : client <-https-> loadbalancer <-http-> webserver(s) When you use $_SERVER["HTTPS"] on tematres code you check the second one so it will be always http.

If we want to enforce I'll more use something like that:

$s = empty($_SERVER["HTTPS"]) ? '' : ($_SERVER["HTTPS"] == "on") ? "s" : "";
$s = ($CFG["https_enforce"]) ? "s" : $s ;

T1loc avatar Jun 02 '20 07:06 T1loc