Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for the X-Forwarded-Host #2891

Merged
merged 1 commit into from
Apr 27, 2020

Conversation

A----
Copy link
Contributor

@A---- A---- commented Apr 24, 2020

Fixes #2877

@A---- A---- force-pushed the feature/x-forwarded-host-support branch from 7e1a645 to 1b8c3ac Compare April 24, 2020 13:05
@rhukster rhukster merged commit 39d0d64 into getgrav:develop Apr 27, 2020
@drzraf
Copy link
Contributor

drzraf commented Apr 29, 2020

  • Contrary to SERVER_NAME which is server provided,
  • ... and HTTP_HOST which is user-provided but often defacto filtered-down by httpd configuration,
  • X_FORWARDED_HOST is under full control of the visitors (except in the rare situations where httpd is configured to deal with this header)

Is user-control of the $hostname variable (and the implication for callers) safe?

@mahagr
Copy link
Member

mahagr commented Apr 30, 2020

We are filtering hostname for illegal letters. We are using host internally to load the correct site configuration and checking against referrer if it's coming from the same site. Maybe something else as well?

@drzraf
Copy link
Contributor

drzraf commented May 4, 2020

Sorry, to worry. I'm maybe a bit over-reactive, but I'm trying to figure-out an adversary use of X-Forwarded-Host: 127.0.0.1 (valid value) or a way to inventory multi-sites setup or just tweak some functions' behavior.

There are quite a lot of references to new Uri() or Uri::getCurrentUri() and some of them make actual use of the $host component for possibly critical guesses.

Just one situation as an example (significant or not?):

// system/src/Grav/Common/Page/Markdown/Excerpts.php : processImageExcerpt()
 $local_file = isset($url_parts['path'])
                && (empty($url_parts['scheme']) || in_array($url_parts['scheme'], ['http', 'https'], true))
                && (empty($url_parts['host']) || $url_parts['host'] === $grav['uri']->host());

With X-Forwarded-Host, an attacker could easily trick this function to make it think the media within a given markdown input is local while it's actually not.

Here there is no subsequent file_get_contents() or fopen(), but we can imagine how, in the future, this could be mistakenly introduced somewhere in the codebase, and easily open unnoticed doors (including within themes/plugins).

@mahagr
Copy link
Member

mahagr commented May 5, 2020

@rhukster I think this is a valid concern and can be used for attacks. We cannot trust X_FORWARDED_HOST which means that it should not be used for anything.

https://www.skeletonscribe.net/2013/05/practical-http-host-header-attacks.html

Looks like this feature is disabled by default in most CMSes.

@rhukster
Copy link
Member

rhukster commented May 5, 2020

I concur with you guys. I should of done more research before approving. It will be removed in next release.

@mahagr
Copy link
Member

mahagr commented May 6, 2020

@rhukster Can we make it configurable and optional instead? I think that in the configurations where it is used, it will be always set by a nearby server/firewall.

@rhukster
Copy link
Member

I've added configuration options for all of these in system.yaml but only 'host' is disabled by default so it maintains backwards compatibility:

http_x_forwarded:                                # Configuration options for the various HTTP_X_FORWARD headers
  protocol: true
  host: false
  port: true
  ip: true

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Handle HTTP_X_FORWARDED_HOST variable
4 participants