diff --git a/internal/httputil/httpapi.go b/internal/httputil/httpapi.go index c42a1dbd0..85ebf6176 100644 --- a/internal/httputil/httpapi.go +++ b/internal/httputil/httpapi.go @@ -240,7 +240,8 @@ func MakeExternalAPI(metricsName string, f func(*http.Request) util.JSONResponse defer span.Finish() req = req.WithContext(opentracing.ContextWithSpan(req.Context(), span)) if forwardedFor := req.Header.Get("X-Forwarded-For"); forwardedFor != "" { - req.RemoteAddr = forwardedFor + ips := strings.Split(forwardedFor, ", ") + req.RemoteAddr = ips[0] } h.ServeHTTP(nextWriter, req) diff --git a/syncapi/sync/requestpool.go b/syncapi/sync/requestpool.go index 57cd96871..046913750 100644 --- a/syncapi/sync/requestpool.go +++ b/syncapi/sync/requestpool.go @@ -192,7 +192,8 @@ func (rp *RequestPool) updateLastSeen(req *http.Request, device *userapi.Device) } if forwardedFor := req.Header.Get("X-Forwarded-For"); forwardedFor != "" { - req.RemoteAddr = forwardedFor + ips := strings.Split(forwardedFor, ", ") + req.RemoteAddr = ips[0] } remoteAddr := req.RemoteAddr if rp.cfg.RealIPHeader != "" {