diff options
| author | Jeff Halter <868228+jhalter@users.noreply.github.com> | 2025-06-29 17:49:35 -0700 |
|---|---|---|
| committer | Jeff Halter <868228+jhalter@users.noreply.github.com> | 2025-06-29 17:49:35 -0700 |
| commit | d2e125bd255e807aa4d374b23eb9c2bb02fe63a3 (patch) | |
| tree | 47001fcf1450533bcade51a6d1d847ad388a6847 /hotline/server.go | |
| parent | 9b6866c80820d22f623a70a8afa0ddf12ada7b0d (diff) | |
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".
Diffstat (limited to 'hotline/server.go')
| -rw-r--r-- | hotline/server.go | 4 |
1 files changed, 2 insertions, 2 deletions
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() |