Skip to content

Commit e6c127c

Browse files
Fix issues with isCurrentlySecure detection and Offloader Header config. (#1462)
1 parent dacba02 commit e6c127c

File tree

3 files changed

+32
-18
lines changed

3 files changed

+32
-18
lines changed

app/code/core/Mage/Core/Controller/Request/Http.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,20 @@ public function getRouteName()
310310
return $this->_route;
311311
}
312312

313+
/**
314+
* Get the request URI scheme
315+
*
316+
* @return string
317+
*/
318+
public function getScheme()
319+
{
320+
return $this->getServer('HTTPS') == 'on'
321+
|| $this->getServer('HTTP_X_FORWARDED_PROTO') == 'https'
322+
|| (Mage::isInstalled() && Mage::app()->getStore()->isCurrentlySecure()) ?
323+
self::SCHEME_HTTPS :
324+
self::SCHEME_HTTP;
325+
}
326+
313327
/**
314328
* Retrieve HTTP HOST
315329
*

app/code/core/Mage/Core/Controller/Varien/Front.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ protected function _processRewriteUrl($url)
330330
* Auto-redirect to base url (without SID) if the requested url doesn't match it.
331331
* By default this feature is enabled in configuration.
332332
*
333-
* @param Zend_Controller_Request_Http $request
333+
* @param Mage_Core_Controller_Request_Http $request
334334
*/
335335
protected function _checkBaseUrl($request)
336336
{

app/code/core/Mage/Core/Model/Store.php

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -795,30 +795,30 @@ public function isFrontUrlSecure()
795795
*/
796796
public function isCurrentlySecure()
797797
{
798-
$standardRule = !empty($_SERVER['HTTPS']) && ('off' != $_SERVER['HTTPS']);
799-
$offloaderHeader = trim((string) Mage::getConfig()->getNode(self::XML_PATH_OFFLOADER_HEADER, 'default'));
798+
if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on') {
799+
return true;
800+
}
800801

801-
if ((!empty($offloaderHeader) && !empty($_SERVER[$offloaderHeader])) || $standardRule) {
802+
if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') {
802803
return true;
803804
}
804805

805-
if (Mage::isInstalled()) {
806-
$secureBaseUrl = Mage::getStoreConfig(Mage_Core_Model_Url::XML_PATH_SECURE_URL);
806+
if (isset($_SERVER['SERVER_PORT']) && (443 == $_SERVER['SERVER_PORT'])) {
807+
return true;
808+
}
807809

808-
if (!$secureBaseUrl) {
809-
return false;
810+
if (Mage::isInstalled()) {
811+
$offloaderHeader = strtoupper(trim((string) Mage::getStoreConfig(self::XML_PATH_OFFLOADER_HEADER)));
812+
if ($offloaderHeader) {
813+
$offloaderHeader = preg_replace('/[^A-Z]+/', '_', $offloaderHeader);
814+
$offloaderHeader = strpos($offloaderHeader, 'HTTP_') === 0 ? $offloaderHeader : 'HTTP_'.$offloaderHeader;
815+
if (!empty($_SERVER[$offloaderHeader]) && $_SERVER[$offloaderHeader] !== 'http') {
816+
return true;
817+
}
810818
}
811-
$urlParts = parse_url($secureBaseUrl);
812-
$scheme = isset($urlParts['scheme']) ? ':' . $urlParts['scheme'] : '';
813-
$port = isset($urlParts['port']) ? ':' . $urlParts['port'] : '';
814-
$isSecure = ($scheme == 'https')
815-
&& isset($_SERVER['SERVER_PORT'])
816-
&& ($port == $_SERVER['SERVER_PORT']);
817-
return $isSecure;
818-
} else {
819-
$isSecure = isset($_SERVER['SERVER_PORT']) && (443 == $_SERVER['SERVER_PORT']);
820-
return $isSecure;
821819
}
820+
821+
return false;
822822
}
823823

824824
/*************************************************************************************

0 commit comments

Comments
 (0)