Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 0af2d62

Browse files
committedJun 6, 2012
Make test for HTTPS protocol compliant with PHP documentation
Prior to this, the protocol was considered to be HTTPS when isset($_SERVER['HTTPS']) is true, while PHP doc[1] states that HTTPS is "Set to a non-empty value if the script was queried through the HTTPS protocol" so the test should be !empty($_SERVER['HTTPS']) instead. This was causing issues with nginx 1.x with php5fastcgi as $_SERVER['HTTPS'] is set but empty, thus MantisBT redirects all http requests to https. The protocol check has been moved to a new function in http_api.php which is then called wherever it is needed. Note that there are several occurences of isset($_SERVER['HTTPS']) in the nusoap library; these have not been modified. Fixes #14333 [1] http://php.net/manual/en/reserved.variables.server.php
1 parent 0777b3b commit 0af2d62

File tree

5 files changed

+26
-22
lines changed

5 files changed

+26
-22
lines changed
 

‎config_defaults_inc.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
$t_protocol = 'http';
8585
if ( isset( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) ) {
8686
$t_protocol= $_SERVER['HTTP_X_FORWARDED_PROTO'];
87-
} else if ( isset( $_SERVER['HTTPS'] ) && ( strtolower( $_SERVER['HTTPS'] ) != 'off' ) ) {
87+
} else if ( !empty( $_SERVER['HTTPS'] ) && ( strtolower( $_SERVER['HTTPS'] ) != 'off' ) ) {
8888
$t_protocol = 'https';
8989
}
9090

‎core/gpc_api.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,19 @@
2020
* @copyright Copyright (C) 2000 - 2002 Kenzaburo Ito - kenito@300baud.org
2121
* @copyright Copyright (C) 2002 - 2012 MantisBT Team - mantisbt-dev@lists.sourceforge.net
2222
* @link http://www.mantisbt.org
23+
*
24+
* @uses http_api.php
2325
*/
2426

27+
require_once( 'http_api.php' );
28+
2529
/**
2630
* Determines (once-off) whether the client is accessing this script via a
2731
* secure connection. If they are, we want to use the Secure cookie flag to
2832
* prevent the cookie from being transmitted to other domains.
2933
* @global bool $g_cookie_secure_flag_enabled
3034
*/
31-
$g_cookie_secure_flag_enabled = isset( $_SERVER['HTTPS'] ) && ( utf8_strtolower( $_SERVER['HTTPS'] ) != 'off' );
35+
$g_cookie_secure_flag_enabled = http_is_protocol_https();
3236

3337
/**
3438
* Determines (once-off) whether the version of PHP executing this script has

‎core/http_api.php

+9-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@
2222
* @link http://www.mantisbt.org
2323
*/
2424

25+
/**
26+
* Checks to see if script was queried through the HTTPS protocol
27+
* @return boolean True if protocol is HTTPS
28+
*/
29+
function http_is_protocol_https() {
30+
return !empty( $_SERVER['HTTPS'] ) && ( utf8_strtolower( $_SERVER['HTTPS'] ) != 'off' );
31+
}
32+
2533
/**
2634
* Check to see if the client is using Microsoft Internet Explorer so we can
2735
* enable quirks and hacky non-standards-compliant workarounds.
@@ -128,7 +136,7 @@ function http_security_headers() {
128136
header( 'X-Frame-Options: DENY' );
129137
$t_avatar_img_allow = '';
130138
if ( config_get_global( 'show_avatar' ) ) {
131-
if ( isset( $_SERVER['HTTPS'] ) && ( utf8_strtolower( $_SERVER['HTTPS'] ) != 'off' ) ) {
139+
if ( http_is_protocol_https() ) {
132140
$t_avatar_img_allow = "; img-src 'self' https://secure.gravatar.com:443";
133141
} else {
134142
$t_avatar_img_allow = "; img-src 'self' http://www.gravatar.com:80";

‎core/user_api.php

+6-14
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,12 @@
2020
* @subpackage UserAPI
2121
* @copyright Copyright (C) 2000 - 2002 Kenzaburo Ito - kenito@300baud.org
2222
* @copyright Copyright (C) 2002 - 2012 MantisBT Team - mantisbt-dev@lists.sourceforge.net
23+
*
24+
* @uses email_api.php
25+
* @uses ldap_api.php
2326
*/
2427

25-
/**
26-
* requires email_api
27-
*/
2828
require_once( 'email_api.php' );
29-
/**
30-
* requires ldap_api
31-
*/
3229
require_once( 'ldap_api.php' );
3330

3431
# ===================================
@@ -803,15 +800,10 @@ function user_get_avatar( $p_user_id, $p_size = 80 ) {
803800
} else {
804801
$t_size = $p_size;
805802

806-
$t_use_ssl = false;
807-
if( isset( $_SERVER['HTTPS'] ) && ( utf8_strtolower( $_SERVER['HTTPS'] ) != 'off' ) ) {
808-
$t_use_ssl = true;
809-
}
810-
811-
if( !$t_use_ssl ) {
812-
$t_gravatar_domain = 'http://www.gravatar.com/';
813-
} else {
803+
if( http_is_protocol_https() ) {
814804
$t_gravatar_domain = 'https://secure.gravatar.com/';
805+
} else {
806+
$t_gravatar_domain = 'http://www.gravatar.com/';
815807
}
816808

817809
$t_avatar_url = $t_gravatar_domain . 'avatar/' . md5( $t_email ) . '?d=identicon&r=G&s=' . $t_size;

‎file_download.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@
119119
# attached files via HTTPS, we disable the "Pragma: no-cache"
120120
# command when IE is used over HTTPS.
121121
global $g_allow_file_cache;
122-
if ( ( isset( $_SERVER["HTTPS"] ) && ( "on" == utf8_strtolower( $_SERVER["HTTPS"] ) ) ) && is_browser_internet_explorer() ) {
122+
if ( http_is_protocol_https() && is_browser_internet_explorer() ) {
123123
# Suppress "Pragma: no-cache" header.
124124
} else {
125125
if ( !isset( $g_allow_file_cache ) ) {
@@ -143,7 +143,7 @@
143143
$finfo = finfo_get_if_available();
144144

145145
$t_content_type = $v_file_type;
146-
146+
147147
$t_content_type_override = file_get_content_type_override ( $t_filename );
148148

149149
# dump file content to the connection.
@@ -159,7 +159,7 @@
159159
$t_content_type = $t_file_info_type;
160160
}
161161
}
162-
162+
163163
if ( $t_content_type_override ) {
164164
$t_content_type = $t_content_type_override;
165165
}
@@ -184,7 +184,7 @@
184184
$t_content_type = $t_file_info_type;
185185
}
186186
}
187-
187+
188188
if ( $t_content_type_override ) {
189189
$t_content_type = $t_content_type_override;
190190
}
@@ -200,7 +200,7 @@
200200
$t_content_type = $t_file_info_type;
201201
}
202202
}
203-
203+
204204
if ( $t_content_type_override ) {
205205
$t_content_type = $t_content_type_override;
206206
}

0 commit comments

Comments
 (0)
Please sign in to comment.