Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to enforce https #52

Open
T1loc opened this issue May 25, 2020 · 2 comments
Open

Add option to enforce https #52

T1loc opened this issue May 25, 2020 · 2 comments

Comments

@T1loc
Copy link
Contributor

T1loc commented May 25, 2020

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
Copy link
Owner

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
Copy link
Contributor Author

T1loc commented Jun 2, 2020

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 ;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants