Skip to content

Commit

Permalink
Added proxy headers verification (close #5)
Browse files Browse the repository at this point in the history
  • Loading branch information
edgardmessias committed Jan 12, 2021
1 parent c37f496 commit f1a69e2
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions inc/provider.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -685,10 +685,28 @@ public function getResourceOwnerDetailsUrl($access_token) {
* @return string
*/
private function getBaseURL() {
$baseURL = (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on") ? "https://" : "http://";
$baseURL .= $_SERVER["SERVER_NAME"];
$baseURL = "";
if (isset($_SERVER['HTTP_X_FORWARDED_PROTO'])) {
$baseURL = ($_SERVER["HTTP_X_FORWARDED_PROTO"] == "https") ? "https://" : "http://";
} else if (isset($_SERVER["HTTPS"])) {
$baseURL = ($_SERVER["HTTPS"] == "on") ? "https://" : "http://";
} else {
$baseURL = "http://";
}
if (isset($_SERVER["HTTP_X_FORWARDED_HOST"])) {
$baseURL .= $_SERVER["HTTP_X_FORWARDED_HOST"];
} else if (isset($_SERVER["HTTP_X_FORWARDED_HOST"])) {
$baseURL .= $_SERVER["HTTP_X_FORWARDED_HOST"];
} else {
$baseURL .= $_SERVER["SERVER_NAME"];
}

$port = $_SERVER["SERVER_PORT"];
if (isset($_SERVER["HTTP_X_FORWARDED_PORT"])) {
$port = $_SERVER["HTTP_X_FORWARDED_PORT"];
}

if ($_SERVER["SERVER_PORT"] != "80" && $_SERVER["SERVER_PORT"] != "443") {
if ($port != "80" && $port != "443") {
$baseURL .= ":" . $_SERVER["SERVER_PORT"];
}
return $baseURL;
Expand Down

0 comments on commit f1a69e2

Please sign in to comment.