Skip to content

Commit

Permalink
Fix realIP logic
Browse files Browse the repository at this point in the history
  • Loading branch information
cl-bvl committed Nov 27, 2023
1 parent 584cb85 commit 40d1f70
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,15 +225,16 @@ func extractIP(req *http.Request) string {
func ExtractIPFromRealIPHeader(options ...TrustOption) IPExtractor {
checker := newIPChecker(options)
return func(req *http.Request) string {
remoteIP := extractIP(req)
realIP := req.Header.Get(HeaderXRealIP)
if realIP != "" {
realIP = strings.TrimPrefix(realIP, "[")
realIP = strings.TrimSuffix(realIP, "]")
if ip := net.ParseIP(realIP); ip != nil && checker.trust(ip) {
realIP = strings.TrimPrefix(realIP, "[")
realIP = strings.TrimSuffix(realIP, "]")
if checker.trust(remoteIP) && realIP != "" {

Check failure on line 232 in ip.go

View workflow job for this annotation

GitHub Actions / check

cannot use remoteIP (variable of type string) as net.IP value in argument to checker.trust (compile)

Check failure on line 232 in ip.go

View workflow job for this annotation

GitHub Actions / check

cannot use remoteIP (variable of type string) as net.IP value in argument to checker.trust (compile)

Check failure on line 232 in ip.go

View workflow job for this annotation

GitHub Actions / ubuntu-latest @ Go 1.18

cannot use remoteIP (variable of type string) as type net.IP in argument to checker.trust

Check failure on line 232 in ip.go

View workflow job for this annotation

GitHub Actions / ubuntu-latest @ Go 1.19

cannot use remoteIP (variable of type string) as type net.IP in argument to checker.trust

Check failure on line 232 in ip.go

View workflow job for this annotation

GitHub Actions / ubuntu-latest @ Go 1.20

cannot use remoteIP (variable of type string) as net.IP value in argument to checker.trust

Check failure on line 232 in ip.go

View workflow job for this annotation

GitHub Actions / ubuntu-latest @ Go 1.21

cannot use remoteIP (variable of type string) as net.IP value in argument to checker.trust

Check failure on line 232 in ip.go

View workflow job for this annotation

GitHub Actions / macos-latest @ Go 1.19

cannot use remoteIP (variable of type string) as type net.IP in argument to checker.trust

Check failure on line 232 in ip.go

View workflow job for this annotation

GitHub Actions / macos-latest @ Go 1.20

cannot use remoteIP (variable of type string) as net.IP value in argument to checker.trust
if ip := net.ParseIP(realIP); ip != nil {
return realIP
}
}
return extractIP(req)
return remoteIP
}
}

Expand Down

0 comments on commit 40d1f70

Please sign in to comment.