-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Closed
Description
Issue Description
ExtractIPFromRealIPHeader does not return what was found in x-real-ip
Line 98 in a97052e
func ExtractIPFromRealIPHeader(options ...TrustOption) IPExtractor { |
func ExtractIPFromRealIPHeader(options ...TrustOption) IPExtractor {
checker := newIPChecker(options)
return func(req *http.Request) string {
directIP := ExtractIPDirect()(req)
realIP := req.Header.Get(HeaderXRealIP)
if realIP != "" {
if ip := net.ParseIP(directIP); ip != nil && checker.trust(ip) {
return realIP
}
}
return directIP
}
}
if realIP != ""
should be if realIP == ""
because ultimately the logic that exists now is when you have real and direct ip it will return direct and not real
Checklist
- [ x] Dependencies installed
- [ x] No typos
- [ x] Searched existing issues and docs
Expected behaviour
when x-real-ip is present the IPExtractor should return that ip instead of the directIP from RemoteAddr
Actual behaviour
ExtractIPFromRealIPHeader returns RemoteAddr if both RemoteAddr and x-real-ip exist
Steps to reproduce
Working code to debug
package main
func main() {
}
Version/commit
Metadata
Metadata
Assignees
Labels
No labels