From af3122f93bad6b07431cd05f3824135a45d9b35d Mon Sep 17 00:00:00 2001 From: Jordan Wright Date: Sun, 11 Oct 2020 13:59:42 -0500 Subject: [PATCH] Adds support for X-Forwarded-For and X-Real-IP headers so that the correct IP address shows up in the logs. Fixes #1999 --- controllers/phish.go | 4 ++++ controllers/route.go | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/controllers/phish.go b/controllers/phish.go index 68701dda..8ca45a4e 100644 --- a/controllers/phish.go +++ b/controllers/phish.go @@ -121,6 +121,10 @@ func (ps *PhishingServer) registerRoutes() { gzipWrapper, _ := gziphandler.NewGzipLevelHandler(gzip.BestCompression) phishHandler := gzipWrapper(router) + // Respect X-Forwarded-For and X-Real-IP headers in case we're behind a + // reverse proxy. + phishHandler = handlers.ProxyHeaders(phishHandler) + // Setup logging phishHandler = handlers.CombinedLoggingHandler(log.Writer(), phishHandler) ps.server.Handler = phishHandler diff --git a/controllers/route.go b/controllers/route.go index d75d981c..6ea299c8 100644 --- a/controllers/route.go +++ b/controllers/route.go @@ -161,6 +161,10 @@ func (as *AdminServer) registerRoutes() { gzipWrapper, _ := gziphandler.NewGzipLevelHandler(gzip.BestCompression) adminHandler = gzipWrapper(adminHandler) + // Respect X-Forwarded-For and X-Real-IP headers in case we're behind a + // reverse proxy. + adminHandler = handlers.ProxyHeaders(adminHandler) + // Setup logging adminHandler = handlers.CombinedLoggingHandler(log.Writer(), adminHandler) as.server.Handler = adminHandler