From 072e52462f766c78ce7b59cdf8475a49347d7ef4 Mon Sep 17 00:00:00 2001 From: Alexander Olofsson <alexander.olofsson@liu.se> Date: Tue, 15 Oct 2019 10:12:26 +0200 Subject: [PATCH] Add config flag to ignore XFH header Fixes #202 --- api/webserver/route_handler.go | 2 +- common/config/config.go | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/api/webserver/route_handler.go b/api/webserver/route_handler.go index 8c5ff41d..709889ce 100644 --- a/api/webserver/route_handler.go +++ b/api/webserver/route_handler.go @@ -31,7 +31,7 @@ type handler struct { func (h handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { isUsingForwardedHost := false - if r.Header.Get("X-Forwarded-Host") != "" { + if r.Header.Get("X-Forwarded-Host") != "" && !config.Get().General.IgnoreForwardedHost { r.Host = r.Header.Get("X-Forwarded-Host") isUsingForwardedHost = true } diff --git a/common/config/config.go b/common/config/config.go index 8a4320eb..2e44d12f 100644 --- a/common/config/config.go +++ b/common/config/config.go @@ -23,10 +23,11 @@ type HomeserverConfig struct { } type GeneralConfig struct { - BindAddress string `yaml:"bindAddress"` - Port int `yaml:"port"` - LogDirectory string `yaml:"logDirectory"` - TrustAnyForward bool `yaml:"trustAnyForwardedAddress"` + BindAddress string `yaml:"bindAddress"` + Port int `yaml:"port"` + LogDirectory string `yaml:"logDirectory"` + TrustAnyForward bool `yaml:"trustAnyForwardedAddress"` + IgnoreForwardedHost bool `yaml:"ignoreForwardedHost"` } type DbPoolConfig struct { @@ -219,10 +220,11 @@ func Get() *MediaRepoConfig { func NewDefaultConfig() *MediaRepoConfig { return &MediaRepoConfig{ General: &GeneralConfig{ - BindAddress: "127.0.0.1", - Port: 8000, - LogDirectory: "logs", - TrustAnyForward: false, + BindAddress: "127.0.0.1", + Port: 8000, + LogDirectory: "logs", + TrustAnyForward: false, + IgnoreForwardedHost: false, }, Database: &DatabaseConfig{ Postgres: "postgres://your_username:your_password@localhost/database_name?sslmode=disable", -- GitLab