Make WordPress Core

Opened 13 years ago

Closed 13 years ago

Last modified 13 years ago

#25222 closed enhancement (duplicate)

Detect https correctly when behind a proxy/loadbalancer

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

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
13 years ago

  • Cc richard@… added
  • Component GeneralHTTP
  • Type defect (bug)enhancement
  • Versiontrunk

#2 @dd32
13 years ago

  • Milestone Awaiting Review
  • Resolutionduplicate
  • Status newclosed

#3 @SergeyBiryukov
13 years ago

  • Version trunk3.6
Note: See TracTickets for help on using tickets.