From 16857146c8961f809f1a6735e84556d5835eaec9 Mon Sep 17 00:00:00 2001 From: Shirshendu Bhowmick <12836504+shirshendubhowmick@users.noreply.github.com> Date: Sat, 9 May 2026 13:45:38 +0530 Subject: [PATCH] refactor(engine): streamline CIDR preparation for trusted proxies --- gin.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/gin.go b/gin.go index d01f344a..00f7d9ef 100644 --- a/gin.go +++ b/gin.go @@ -418,11 +418,13 @@ func (engine *Engine) prepareTrustedCIDRs() ([]netip.Prefix, error) { if err != nil { return cidrs, &net.ParseError{Type: "IP address", Text: trustedProxy} } - if addr.Unmap().Is4() { - trustedProxy += "/32" - } else { - trustedProxy += "/128" + addr = addr.Unmap() + bits := 128 + if addr.Is4() { + bits = 32 } + cidrs = append(cidrs, netip.PrefixFrom(addr, bits)) + continue } prefix, err := netip.ParsePrefix(trustedProxy) if err != nil {