summaryrefslogtreecommitdiff
path: root/service/http/handler.go
diff options
context:
space:
mode:
authorSmolyakov <[email protected]>2019-09-01 15:36:42 +0300
committerSmolyakov <[email protected]>2019-09-01 15:36:42 +0300
commit488a9774636ece92e730a41092403410910d566f (patch)
treeed1138e5f2af51089650f16fde471738ca06565e /service/http/handler.go
parent49e002c11e5cc915d80efa58611f4c4a72de7bb2 (diff)
Use last IP address from X-Forwarded-For without validation of trusty
Diffstat (limited to 'service/http/handler.go')
-rw-r--r--service/http/handler.go11
1 files changed, 8 insertions, 3 deletions
diff --git a/service/http/handler.go b/service/http/handler.go
index 254f5ca6..19179b72 100644
--- a/service/http/handler.go
+++ b/service/http/handler.go
@@ -152,12 +152,17 @@ func (h *Handler) resolveIP(r *Request) {
}
if r.Header.Get("X-Forwarded-For") != "" {
- for _, addr := range strings.Split(r.Header.Get("X-Forwarded-For"), ",") {
- addr = strings.TrimSpace(addr)
- if h.cfg.IsTrusted(addr) {
+ ips := strings.Split(r.Header.Get("X-Forwarded-For"), ",")
+ ipCount := len(ips)
+
+ for i := ipCount - 1; i >= 0; i-- {
+ addr := strings.TrimSpace(ips[i])
+ if h.cfg.IsValid(addr) {
r.RemoteAddr = addr
+ return
}
}
+
return
}