Make WordPress Core

Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#25222 closed enhancement (duplicate)

Detect https correctly when behind a proxy/loadbalancer

Reported by: xeli's profile xeli Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.6
Component: HTTP API Keywords:
Focuses: Cc:

Description

The wordpress is_ssl() does not check the HTTP-X-Forwarded-Proto http header to determine if the site is on ssl.

This cause all assets (css/js/images) to be served as http rather than https.

The fix is rather easy in wp-include/functions.php change:

function is_ssl() {
    if ( isset($_SERVER['HTTPS']) ) {
        if ( 'on' == strtolower($_SERVER['HTTPS']) )
            return true;
        if ( '1' == $_SERVER['HTTPS'] )
            return true;
    } elseif ( isset($_SERVER['SERVER_PORT']) && ( '443' == $_SERVER['SERVER_PORT'] ) ) {
        return true;
    }
    return false;
}

to

function is_ssl() {
    if ( isset($_SERVER['HTTPS']) ) {
        if ( 'on' == strtolower($_SERVER['HTTPS']) )
            return true;
        if ( '1' == $_SERVER['HTTPS'] )
            return true;
    } elseif ( isset($_SERVER['SERVER_PORT']) && ( '443' == $_SERVER['SERVER_PORT'] ) ) {
        return true;
    } elseif ( isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && ( $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' ) {
        return true;
    }
    return false;
}

Change History (3)

#1 @xeli
11 years ago

  • Cc richard@… added
  • Component changed from General to HTTP
  • Type changed from defect (bug) to enhancement
  • Version set to trunk

#2 @dd32
11 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

#3 @SergeyBiryukov
11 years ago

  • Version changed from trunk to 3.6
Note: See TracTickets for help on using tickets.