-
Notifications
You must be signed in to change notification settings - Fork 11
$_SERVER['HTTPS'] not set when php page accessed from HTTPS #6
Description
As described into http://fr2.php.net/manual/en/reserved.variables.server.php when a php script is handling an HTTPS request, the $_SERVER['HTTPS'] is expec ted to be set.
This is not currently the case as shown on the sample php-info running from the cf-php-apache-buildpack:
https://php-info.cfapps.io/info.php
When an app is running within the cf-php-apache-buildpack, the load balancer before the gorouter (AWS ELB for run.pivotal.io or HAProxy or Nginx such as in https://github.com/cloudfoundry-community/sslproxy-boshrelease) converts the received HTTPS traffic into HTTP and adds the x-forwarded-proto header and x-forwarded-for.
A possible workaround for php apps is to perform the test themselves:
if(isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https'){
$_SERVER['HTTPS']='on';
}
Some standard apps already perform such tests (e.g. https://drupal.org/node/313145 ), however others may break when accessed from https as they will detect that incoming traffic comes from HTTP, and may try to redirect to HTTPS urls, resulting into infinite redirection loops.
It would be great to have the cf-php-apache-buildpack automatically process the HTTP_X_FORWARDED_PROTO, in a similar way the java-buildpack does it with the RemoteIpValve cf https://github.com/cloudfoundry/java-buildpack/blob/master/resources/tomcat/conf/server.xml and http://tomcat.apache.org/tomcat-7.0-doc/api/org/apache/catalina/valves/RemoteIpValve.html
I searched for a similar apache module but only found so far:
- http://httpd.apache.org/docs/trunk/en/mod/mod_remoteip.html#processing which only deals with the remote ip and not remote protocol (I'll open a second issue for the remote ip not being properly exposed to php apps)
- mod_rpaf seems to support X-FORWARDED-PROTO see Look at X-Forwarded-Proto for the HTTPS environment variable gnif/mod_rpaf#11 This needs testing and it does not seem to be included into recent apache distributions. Also needs a further patch to remove XHTTPS header support that cloudfoundry would not skip if present in the https request.
If some php instructions could be included by the php interpreter prio to every HTTP request handling then the php snipnet above could be added.