Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions lib/Saml2/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -573,8 +573,8 @@ public static function getSelfPort()
$portnumber = null;
if (self::$_port) {
$portnumber = self::$_port;
} else if (self::getProxyVars() && isset($_SERVER["HTTP_X_FORWARDED_PORT"])) {
$portnumber = $_SERVER["HTTP_X_FORWARDED_PORT"];
} else if (self::getProxyVars() && self::determinePortFromProxyVars() !== null) {
$portnumber = self::determinePortFromProxyVars();
} else if (isset($_SERVER["SERVER_PORT"])) {
$portnumber = $_SERVER["SERVER_PORT"];
} else {
Expand All @@ -591,6 +591,23 @@ public static function getSelfPort()
return $portnumber;
}

/**
* @return null|string The port number inferred from the proxy variables (HTTP_X_FORWARDED_...)
*/
private static function determinePortFromProxyVars()
{
if (isset($_SERVER["HTTP_X_FORWARDED_PORT"])) {
return $_SERVER["HTTP_X_FORWARDED_PORT"];
} else if (isset($_SERVER["HTTP_X_FORWARDED_PROTO"])) {
if ($_SERVER["HTTP_X_FORWARDED_PROTO"] == 'https') {
return '443';
} elseif ($_SERVER["HTTP_X_FORWARDED_PROTO"] == 'http') {
return '80';
}
}
return null;
}

/**
* Checks if https or http.
*
Expand Down