Skip to content

Commit

Permalink
ENHANCEMENT: Ensure that forceSSL and protocol detection respects the…
Browse files Browse the repository at this point in the history
… X-Forwarded-Protocol header.
  • Loading branch information
Sam Minnee committed Feb 2, 2012
1 parent bf4476a commit 921bf9a
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion core/control/Director.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@ static function protocolAndHost() {
* @return String * @return String
*/ */
static function protocol() { static function protocol() {
if(isset($_SERVER['HTTP_X_FORWARDED_PROTOCOL']) && strtolower($_SERVER['HTTP_X_FORWARDED_PROTOCOL']) == 'https') return "https://";
return (isset($_SERVER['SSL']) || (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off')) ? 'https://' : 'http://'; return (isset($_SERVER['SSL']) || (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off')) ? 'https://' : 'http://';
} }


Expand Down Expand Up @@ -646,7 +647,7 @@ static function forceSSL($patterns = null) {
$matched = true; $matched = true;
} }


if($matched && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == 'off')) { if($matched && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == 'off') && !(isset($_SERVER['HTTP_X_FORWARDED_PROTOCOL']) && strtolower($_SERVER['HTTP_X_FORWARDED_PROTOCOL']) == 'https')) {
$destURL = str_replace('http:', 'https:', Director::absoluteURL($_SERVER['REQUEST_URI'])); $destURL = str_replace('http:', 'https:', Director::absoluteURL($_SERVER['REQUEST_URI']));


// This coupling to SapphireTest is necessary to test the destination URL and to not interfere with tests // This coupling to SapphireTest is necessary to test the destination URL and to not interfere with tests
Expand Down

0 comments on commit 921bf9a

Please sign in to comment.