From 5c91621223aa20c736d9aa3aac5b5f866c95e6c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0ediv=C3=BD?= Date: Sun, 8 Sep 2024 23:26:17 +0200 Subject: [PATCH] legacy: fix banned ip. --- server/internal/http/legacy/handler.go | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/server/internal/http/legacy/handler.go b/server/internal/http/legacy/handler.go index edaf511d..5754509a 100644 --- a/server/internal/http/legacy/handler.go +++ b/server/internal/http/legacy/handler.go @@ -383,21 +383,17 @@ func (h *LegacyHandler) ban(sessionId string) error { } func (h *LegacyHandler) isBanned(r *http.Request) bool { - ipPort := r.RemoteAddr - ip, _, err := net.SplitHostPort(ipPort) - if err != nil { - h.logger.Error().Err(err).Msg("couldn't split host and port") - return false - } - + ip := getIp(r) _, ok := h.bannedIPs[ip] return ok } func getIp(r *http.Request) string { - ipPort := r.RemoteAddr - ip, _, err := net.SplitHostPort(ipPort) + ip, _, err := net.SplitHostPort(r.RemoteAddr) if err != nil { + if e, ok := err.(*net.AddrError); ok && e.Err == "missing port in address" { + return r.RemoteAddr + } return "" }