{"record":{"id":"d965562a413a5a4a","repo":"gofiber/fiber","slug":"remote-address-cannot-be-empty","errorCode":null,"errorMessage":"remote address cannot be empty","messagePattern":"remote address cannot be empty","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"middleware/adaptor/adaptor.go","lineNumber":222,"sourceCode":"\t\t\tdst[key] = append(existing, val)\n\t\t\tcontinue\n\t\t}\n\n\t\tif vals == nil {\n\t\t\tvals = make([]string, 0, count)\n\t\t} else if len(vals) == cap(vals) {\n\t\t\tdst[key] = []string{val}\n\t\t\tcontinue\n\t\t}\n\n\t\ti := len(vals)\n\t\tvals = append(vals, val)\n\t\tdst[key] = vals[i : i+1 : i+1]\n\t}\n}\n\nvar (\n\tErrRemoteAddrEmpty   = errors.New(\"remote address cannot be empty\")\n\tErrRemoteAddrTooLong = errors.New(\"remote address too long\")\n)\n\n// HTTPHandlerFunc wraps net/http handler func to fiber handler\nfunc HTTPHandlerFunc(h http.HandlerFunc) fiber.Handler {\n\treturn HTTPHandler(h)\n}\n\n// HTTPHandler wraps net/http handler to fiber handler\nfunc HTTPHandler(h http.Handler) fiber.Handler {\n\thandler := fasthttpadaptor.NewFastHTTPHandler(h)\n\treturn func(c fiber.Ctx) error {\n\t\thandler(c.RequestCtx())\n\t\treturn nil\n\t}\n}\n\n// HTTPHandlerWithContext is like HTTPHandler, but additionally stores Fiber’s user context in the request context","sourceCodeStart":204,"sourceCodeEnd":240,"githubUrl":"https://github.com/gofiber/fiber/blob/a105acad6c1e4576a77f01e02973f67e962bb58d/middleware/adaptor/adaptor.go#L204-L240","documentation":"Returned by middleware/adaptor.resolveRemoteAddr when the remoteAddr argument is the empty string. resolveRemoteAddr converts a net/http-style RemoteAddr into a net.Addr when bridging requests into Fiber; an empty address cannot be turned into a meaningful TCP/Unix peer. The check runs before any parsing so malformed input fails fast rather than reaching the resolver.","triggerScenarios":"Calling an adaptor helper that resolves the peer address (e.g. when converting a net/http request whose RemoteAddr field was never populated) with an empty string. Happens with in-process clients or test harnesses that build a fake http.Request without setting RemoteAddr.","commonSituations":"Unit tests constructing http.Request{} manually; a reverse proxy that strips peer info before the request reaches the adaptor; an internal pipeline request that has no real socket peer.","solutions":["Ensure the inbound request carries a populated RemoteAddr (\"ip:port\") before it reaches the adaptor conversion path.","If you control the caller, default RemoteAddr to a known sentinel (e.g. \"127.0.0.1:0\") for synthetic requests.","Guard the conversion: skip resolveRemoteAddr when RemoteAddr is empty and proceed without peer info."],"exampleFix":"// before\naddr, err := resolveRemoteAddr(r.RemoteAddr, nil)\n// after\nremote := r.RemoteAddr\nif remote == \"\" {\n    remote = \"127.0.0.1:0\"\n}\naddr, err := resolveRemoteAddr(remote, nil)","handlingStrategy":"validation","validationCode":"if r.RemoteAddr == \"\" {\n    r.RemoteAddr = \"127.0.0.1:0\" // synthetic peer for in-process requests\n}","typeGuard":null,"tryCatchPattern":"addr, err := adaptor.ResolveRemoteAddr(remote, local)\nif err != nil {\n    if errors.Is(err, adaptor.ErrRemoteAddrEmpty) {\n        // proceed without a peer addr, or log and reject\n    }\n    return err\n}","preventionTips":["Treat RemoteAddr as required input for any net/http -> Fiber conversion path.","In tests, always set http.Request.RemoteAddr to a synthetic value.","Validate upstream request shape at the trust boundary before adapting."],"tags":["adaptor","network","request-conversion"],"backgroundTag":null,"analyzedSha":"a105acad6c1e4576a77f01e02973f67e962bb58d","analyzedAt":"2026-08-11T17:33:26.942Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}