From 9413fc19ffe10f476b60e68520ac7e3d2cac00b6 Mon Sep 17 00:00:00 2001 From: Livio Amstutz Date: Tue, 20 Jul 2021 10:10:48 +0200 Subject: [PATCH] fix: parsing of ip address (#2045) --- internal/api/http/header.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/internal/api/http/header.go b/internal/api/http/header.go index 858312789a..beb3b53a57 100644 --- a/internal/api/http/header.go +++ b/internal/api/http/header.go @@ -77,7 +77,8 @@ func RemoteIPStringFromRequest(r *http.Request) string { if ok { return ip } - return r.RemoteAddr + host, _, _ := net.SplitHostPort(r.RemoteAddr) + return host } func GetAuthorization(r *http.Request) string { @@ -91,7 +92,7 @@ func GetOrgID(r *http.Request) string { func GetForwardedFor(headers http.Header) (string, bool) { forwarded, ok := headers[ForwardedFor] if ok { - ip := strings.Split(forwarded[0], ", ")[0] + ip := strings.TrimSpace(strings.Split(forwarded[0], ",")[0]) if ip != "" { return ip, true }