Skip to content

🐛 [Bug]: IP() returning weird websocket string #1800

@mhclaudiu

Description

@mhclaudiu

Bug Description

Hello everyone and team, from time to time i'm experiencing some weird behaviour with the returning .IP() value.
I'm using nginx in front, having this config

proxy_http_version 1.1;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Scheme $scheme;
proxy_set_header X-Forwarded-Uri $request_uri;

And in the app i have a simple rate-limit function

router := fiber.New(fiber.Config{
		ProxyHeader:  "X-Real-IP",
		TrustProxy:   true,
		TrustProxyConfig: fiber.TrustProxyConfig{
			Loopback: true,
			Private:  true,
		},
	})

router.Use(logger.New(logger.Config{
		Format: "[${time}] ${ip} - ${status} - ${latency} - ${protocol}  ${method}  ${url} - ${error}\n",
		Stream: os.Stdout,
		Next: func(f fiber.Ctx) bool {
			return websocket.IsWebSocketUpgrade(f) || f.IsWebSocket() || f.Path() == strings.TrimRight(c.Config.API.Path, "/")+"/health"
		},
}))

ws := router.Group(c.Config.API.PathWS)
ws.Use("/", func(f fiber.Ctx) error {})
ws.Get("/", func(f fiber.Ctx) error {

		if websocket.IsWebSocketUpgrade(f) {
			return f.Next()
		}
		return fiber.ErrUpgradeRequired
	}, handler.Events())

api := router.Group(c.Config.API.Path)
api.Use(handler.RateLimit)
func (c *Config) RateLimit(f fiber.Ctx) error {

	if !c.Config.API.RateLimit.Enabled || websocket.IsWebSocketUpgrade(f) || f.IsWebSocket() {

		return f.Next()
	}

	guestIP := f.IP()
	log.Println("_" + guestIP + "_")
       
       // the rest of the logic for either update or add the values / guest
}

func (c *Config) CleanupRateLimits() {

	if !c.Config.API.RateLimit.Enabled {
		return
	}

	// logic here to the 'removed' variable

	for _, addr := range removed {

		c.Log.Add(logging.Entry{
			Notice: fmt.Sprintf("-> Guest '%s' was automatically cleaned out", addr),
		})
	}
}

I have added some logging to debug it further, and from time to time i see this in the logs

2026/04/10 04:04:32 54.37.168.222
2026/04/10 04:05:03 89.125.209.209
[04:05:03] 89.125.209.209 - 404 - 151.407µs - HTTP/1.1 GET /xmlrpc.php - -
2026/04/10 04:05:25 165.227.7.228
[04:05:25] 165.227.7.228 - 404 - 165.952µs - HTTP/1.1 GET /xmlrpc.php - -
[04:05:26] 165.227.7.228 - 404 - 110.085µs - HTTP/1.1 GET /wp-login.php - -
2026/04/10 04:05:26 165.227.7.228
2026/04/10 05:05:26 [HANDLERS/RATE_LIMIT:232] -> Guest '54.37.168.222' was automatically cleaned out
2026/04/10 05:05:26 [HANDLERS/RATE_LIMIT:232] -> Guest '89.125.209.209' was automatically cleaned out
2026/04/10 05:05:26 [HANDLERS/RATE_LIMIT:232] -> Guest 'websocket.228' was automatically cleaned out

Somehow the value of f.IP() is becoming websocket.228 and my assumption is that would be for the 165.227.7.228 IP as the other ones above were correctly addressed. I really can not understand what is this exactly.

How to Reproduce

Code added above

Expected Behavior

Returning the correct IP value

Fiber Version

v3.1.0

Code Snippet (optional)

package main

import "github.com/gofiber/fiber/v3"
import "log"

func main() {
  app := fiber.New()

  // Steps to reproduce

  log.Fatal(app.Listen(":3000"))
}

Checklist:

  • I agree to follow Fiber's Code of Conduct.
  • I have checked for existing issues that describe my problem prior to opening this one.
  • I understand that improperly formatted bug reports may be closed without explanation.

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

Status
Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions