From d2e125bd255e807aa4d374b23eb9c2bb02fe63a3 Mon Sep 17 00:00:00 2001 From: Jeff Halter <868228+jhalter@users.noreply.github.com> Date: Sun, 29 Jun 2025 17:49:35 -0700 Subject: Fix IPv6 address parsing in IP extraction Replace string splitting with net.SplitHostPort to properly handle both IPv4 and IPv6 addresses. Fixes issue where IPv6 addresses like [::1]:8080 were incorrectly parsed as "[" instead of "::1". --- hotline/server.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'hotline/server.go') diff --git a/hotline/server.go b/hotline/server.go index fb75039..98b6132 100644 --- a/hotline/server.go +++ b/hotline/server.go @@ -228,7 +228,7 @@ func (s *Server) Serve(ctx context.Context, ln net.Listener) error { } go func() { - ipAddr := strings.Split(conn.RemoteAddr().(*net.TCPAddr).String(), ":")[0] + ipAddr, _, _ := net.SplitHostPort(conn.RemoteAddr().String()) connCtx := context.WithValue(ctx, contextKeyReq, requestCtx{ remoteAddr: conn.RemoteAddr().String(), @@ -422,7 +422,7 @@ func (s *Server) handleNewConnection(ctx context.Context, rwc io.ReadWriteCloser } // Check if remoteAddr is present in the ban list, we do this after we have the login name - ipAddr := strings.Split(remoteAddr, ":")[0] + ipAddr, _, _ := net.SplitHostPort(remoteAddr) if s.Redis != nil { // Redis-based ban check bannedUser, _ := s.Redis.SIsMember(ctx, "mobius:banned:users", login).Result() -- cgit