Skip to content

Commit 118564b

Browse files
author
Nikita Krasnoyartsev
committed
fix multiple x_forwarded_proto
1 parent 7cd23f9 commit 118564b

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/HttpClient/Util.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,22 @@ public static function getCurrentUrl($requestUri = false)
8989
$protocol = 'http://';
9090

9191
if (($collection->get('HTTPS') && $collection->get('HTTPS') !== 'off') ||
92-
$collection->get('HTTP_X_FORWARDED_PROTO') === 'https') {
92+
self::isXForwardedProtoHttps($collection->get('HTTP_X_FORWARDED_PROTO'))) {
9393
$protocol = 'https://';
9494
}
9595

9696
return $protocol .
9797
$collection->get('HTTP_HOST') .
9898
$collection->get($requestUri ? 'REQUEST_URI' : 'PHP_SELF');
9999
}
100+
101+
public static function isXForwardedProtoHttps($xForwardedProto)
102+
{
103+
$protos = explode(',', (string)$xForwardedProto);
104+
if (count($protos) > 0) {
105+
return trim($protos[0]) === 'https';
106+
}
107+
108+
return false;
109+
}
100110
}

src/Thirdparty/OpenID/LightOpenID.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
use Hybridauth\Exception\Exception;
1313
use Hybridauth\Exception\ExceptionInterface;
14+
use Hybridauth\HttpClient\Util;
1415

1516
/**
1617
* Class ErrorException
@@ -255,7 +256,7 @@ protected function get_realm_protocol()
255256
if (!empty($_SERVER['HTTPS'])) {
256257
$use_secure_protocol = ($_SERVER['HTTPS'] !== 'off');
257258
} elseif (isset($_SERVER['HTTP_X_FORWARDED_PROTO'])) {
258-
$use_secure_protocol = ($_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https');
259+
$use_secure_protocol = (Util::isXForwardedProtoHttps($_SERVER['HTTP_X_FORWARDED_PROTO']));
259260
} elseif (isset($_SERVER['HTTP__WSSC'])) {
260261
$use_secure_protocol = ($_SERVER['HTTP__WSSC'] == 'https');
261262
} else {

0 commit comments

Comments
 (0)