clientIP extracts the caller IP for per-IP limiting. It trusts only CF-Connecting-IP (set by Cloudflare and stripped from inbound requests at the edge), NOT X-Forwarded-For: an attacker can prepend an arbitrary XFF entry and Cloudflare appends the real client IP rather than replacing it, so the left
(r *http.Request)
| 145 | // to XFF. Mirrors agent.clientIP and oauth dcrSourceIP so every per-IP |
| 146 | // limiter keys identically. |
| 147 | func clientIP(r *http.Request) string { |
| 148 | if ip := strings.TrimSpace(r.Header.Get("CF-Connecting-IP")); ip != "" { |
| 149 | return ip |
| 150 | } |
| 151 | if host, _, err := net.SplitHostPort(r.RemoteAddr); err == nil { |
| 152 | return host |
| 153 | } |
| 154 | return r.RemoteAddr |
| 155 | } |