diff --git a/api/webserver/route_handler.go b/api/webserver/route_handler.go index 5d08e912be47aeea3f7fbd016f8f6f1bad7a9e25..218905f7ce7ea37b2f26c4be8c66bf90668e70ca 100644 --- a/api/webserver/route_handler.go +++ b/api/webserver/route_handler.go @@ -32,7 +32,7 @@ type handler struct { func (h handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { isUsingForwardedHost := false - if r.Header.Get("X-Forwarded-Host") != "" && !config.Get().General.IgnoreForwardedHost { + if r.Header.Get("X-Forwarded-Host") != "" && config.Get().General.UseForwardedHost { r.Host = r.Header.Get("X-Forwarded-Host") isUsingForwardedHost = true } diff --git a/common/config/config.go b/common/config/config.go index de873f1b8b4e5ca69f34f347f9e0aaa324f5d349..234eb527df558f3d3b10a5e49bcc105be93a0dde 100644 --- a/common/config/config.go +++ b/common/config/config.go @@ -24,11 +24,11 @@ type HomeserverConfig struct { } type GeneralConfig struct { - BindAddress string `yaml:"bindAddress"` - Port int `yaml:"port"` - LogDirectory string `yaml:"logDirectory"` - TrustAnyForward bool `yaml:"trustAnyForwardedAddress"` - IgnoreForwardedHost bool `yaml:"ignoreForwardedHost"` + BindAddress string `yaml:"bindAddress"` + Port int `yaml:"port"` + LogDirectory string `yaml:"logDirectory"` + TrustAnyForward bool `yaml:"trustAnyForwardedAddress"` + UseForwardedHost bool `yaml:"useForwardedHost"` } type DbPoolConfig struct { @@ -228,11 +228,11 @@ func Get() *MediaRepoConfig { func NewDefaultConfig() *MediaRepoConfig { return &MediaRepoConfig{ General: &GeneralConfig{ - BindAddress: "127.0.0.1", - Port: 8000, - LogDirectory: "logs", - TrustAnyForward: false, - IgnoreForwardedHost: false, + BindAddress: "127.0.0.1", + Port: 8000, + LogDirectory: "logs", + TrustAnyForward: false, + UseForwardedHost: true, }, Database: &DatabaseConfig{ Postgres: "postgres://your_username:your_password@localhost/database_name?sslmode=disable", diff --git a/config.sample.yaml b/config.sample.yaml index 02a58f4a2982e2946a274b7f3fe38146178cf335..31550cf38e1d2a54ba4cad636c360a2fa4606bb6 100644 --- a/config.sample.yaml +++ b/config.sample.yaml @@ -12,6 +12,11 @@ repo: # header, but validates it to ensure the IP being given makes sense. trustAnyForwardedAddress: false + # If false, the media repo will not use the X-Forwarded-Host header commonly added by reverse proxies. + # Typically this should remain as true, though in some circumstances it may need to be disabled. + # See https://github.com/turt2live/matrix-media-repo/issues/202 for more information. + useForwardedHost: true + # The database configuration for the media repository database: # Currently only "postgres" is supported.