tematres / TemaTres-Vocabulary-Server

Web application for management formal representations of knowledge, like controlled vocabularies, taxonomies, thesauri and glossaries
https://vocabularyserver.com
124 stars 53 forks source link

Add option to enforce https #52

Open T1loc opened 4 years ago

T1loc commented 4 years ago

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;
}
tematres commented 4 years ago

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?

T1loc commented 4 years ago

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 ;