backport of #313145: Support X-Forwarded-* HTTP headers alternates
When the trusted proxies are set and reverse_proxy is enabled, Symfony will automatically pickup the default X-Forwarded-* headers. However, Drupal only allows you to change the X-Forwarded-For header. Drupal does not support changing the name of any other header in the X-Forwarded family.

Taking, for instance, the X-Forwarded-Proto (XFP) header, which is included as part of the request sent to the back-end web server by many crypto-offloaders and load balancer. This header allows the load-balanced/crypto-offloaded application to know the protocol used by the client to reach the load balancer, allowing the application to generate links with the correct protocol. However, some systems use different headers for the same purpose. An example is the "Microsoft Internet Security and Acceleration Server", which uses the Front-End-Https for similar purposes.

Benefit:

Without a correct scheme/protocol, various things break -- most visibly the stylesheets and javascripts, AJAX calls and the Drupal installer, because callback URLs are built on an incorrect scheme.

Cost:

The patch only introduces extra function calls for users already using a reverse proxy. Since that is not the case for most users, there is no cost for them.

Note:

It is possible to set $base_root manually in settings.php. But using this patch will allow Drupal to work in this sort of environment as it is already documented, without special care being taken to create settings.php ahead of time.

Beta phase evaluation

Reference: https://www.drupal.org/core/beta-changes
Issue category Bug because this functionality is present in symfony, but Drupal only allows the client ip header to be changed. It also affects the usability of Drupal, as Drupal doesn't work with some crypto offloaders.
Issue priority Major because this prevents all crypto offloaders/load balancers not using the de-facto standard X-Forwarded headers from working with Drupal.
Prioritized changes The main goal of this issue is to improve the usability of Drupal from a system administrator point of view, by improving the support for of crypto offloaders.

Manual testing steps

If you want to test this patch manually, without setting up Varnish, you must:

  1. Set up your webserver so it can serve requests over HTTPS.
  2. Set up your webserver so it adds an X-Forwarded-Proto header set to the value "https". In Apache, this looks like: RequestHeader set X-Forwarded-Proto "https"
  3. Ensure your webserver is using the new configuration (e.g.: sudo /etc/init.d/apache2 reload).
  4. Optionally, perform a fresh install of Drupal. Otherwise, have a working copy of Drupal.
  5. In settings.php, ensure the #$base_url = 'http://example.com"; line is commented.
  6. In settings.php, un-comment the $conf['reverse_proxy'] = TRUE; line.
  7. In settings.php, un-comment the $conf['reverse_proxy_addresses'] = array(); line and add your client IP to the array (most likely 127.0.0.1).
  8. Flush all Drupal caches (e.g.: drush -y cc all).
  9. Go to your example site over the HTTP protocol (e.g.: http://example.com). View the source.
    • If the patch is applied and working correctly, all your stylesheets, scripts, etc. will use the https protocol.
      Note that most links on the front page of a default Drupal installation are generated relative to the server root (e.g.: <a href="/user/login"></a>) so clicking on them will not generally take you to the HTTPS version (you'll need the Secure Login or Secure Pages modules for that).
    • If the patch is not applied, or does not work correctly, all your stylesheets, scripts, etc. will use the http protocol.

Comments

joseph.olstad created an issue. See original summary.

joseph.olstad’s picture

StatusFileSize
new2.43 KB

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 2: support-proto-header-2970929-2.patch, failed testing. View results

joseph.olstad’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 2: support-proto-header-2970929-2.patch, failed testing. View results

joseph.olstad’s picture

Status: Needs work » Reviewed & tested by the community

this is working locally, not sure why the testbot is not working.
this passed tests here:
#313145-167: Support X-Forwarded-* HTTP headers alternates

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 2: support-proto-header-2970929-2.patch, failed testing. View results

joseph.olstad’s picture

Status: Needs work » Reviewed & tested by the community
Related issues: +#2970950: D7 test runner not working since may 4th 2018 'Composer command failed'

I've openned an issue with the testrunner queue

mustanggb’s picture

I found this issue due to the usual "mixed content" errors whilst attempting an install over https with a reverse proxy to an http backend.

So obviously I'm disappointed this doesn't support installs, hopefully a better option can be found for this aspect at some point.

But for regular post-install stuff it works a treat.

joseph.olstad’s picture

from what I read up in the original issue #313145: Support X-Forwarded-* HTTP headers alternates this was already included in D8 as-is,
The documentation is included in the patch, the installation procedure for proxy/https will be documented in the settings.php , I think this is fine considering the advanced setup you're using.

crutch’s picture

Thanks joseph.olstad for reference to the D7 issue from this issue https://www.drupal.org/project/drupal/issues/2984933

We just applied this patch to multiple sites in a vhost/lamp environment, removed load balancer 2 listening on port 443, enabled ssl termination on load balancer 1, installed SSL on it.

Restarted Varnish, restarted load balanced servers.

Since initial install of ssl on June 20 without patch, we may have some file inconsistencies, however, when testing uploading of files the errors now seem to be gone.

All header files are loading https as expected.

Currently, all seems okay but will be monitoring over the next several days.

joseph.olstad’s picture

Issue tags: +Drupal 7.60 target

not surprising to be working as designed as this is already RTBC and virtually the same change was committed to D8.

joseph.olstad’s picture

Issue tags: -Drupal 7.60 target +Drupal 7.70 target

Bumping to 7.70, this didn't make it into 7.60

joseph.olstad’s picture

wondering if this should be a 7.64 target?

joseph.olstad’s picture

see what the core maintainers say about this.

mustanggb’s picture

pandaski’s picture

Somehow I am thinking we shall put the seckit module into core :)

Drupal needs more love to security features from the core.

mustanggb’s picture

Issue tags: -Drupal 7.68 target +Drupal 7.69 target
mustanggb’s picture

Issue tags: -Drupal 7.69 target +Drupal 7.70 target
joseph.olstad’s picture

fabianx’s picture

I am not sure about this issue:

a) It's not a real backport and changes different things.
b) Just fixing is_https is usually not enough, because then Drupal serves via https and Apache serves files via http (which is effecting redirects via RewriteRule e.g.)

I can see that it's bad to always have to put `SetEnvIf X_FORWARDED_PROTO https HTTPS=on` into e.g. the Apache configuration, but it's usually the right way to ensure both Drupal and the webserver know about being behind an https endpoint terminated elsewhere.

Thoughts?

Status: Reviewed & tested by the community » Closed (outdated)

Automatically closed because Drupal 7 security and bugfix support has ended as of 5 January 2025. If the issue verifiably applies to later versions, please reopen with details and update the version.