Changeset 370 in code for trunk/server.go
- Timestamp:
- Jul 22, 2020, 3:03:01 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/server.go
r348 r370 12 12 "gopkg.in/irc.v3" 13 13 "nhooyr.io/websocket" 14 15 "git.sr.ht/~emersion/soju/config" 14 16 ) 15 17 … … 42 44 43 45 type Server struct { 44 Hostname string 45 Logger Logger 46 RingCap int 47 HistoryLimit int 48 LogPath string 49 Debug bool 50 HTTPOrigins []string 46 Hostname string 47 Logger Logger 48 RingCap int 49 HistoryLimit int 50 LogPath string 51 Debug bool 52 HTTPOrigins []string 53 AcceptProxyIPs config.IPSet 51 54 52 55 db *DB … … 154 157 } 155 158 156 is Loopback:= false159 isProxy := false 157 160 if host, _, err := net.SplitHostPort(req.RemoteAddr); err == nil { 158 161 if ip := net.ParseIP(host); ip != nil { 159 is Loopback = ip.IsLoopback()162 isProxy = s.AcceptProxyIPs.Contains(ip) 160 163 } 161 164 } 162 165 163 // Only trust X-Forwarded-* header fields if this is a loopback connection,166 // Only trust X-Forwarded-* header fields if this is a trusted proxy IP 164 167 // to prevent users from spoofing the remote address 165 168 remoteAddr := req.RemoteAddr 166 169 forwardedHost := req.Header.Get("X-Forwarded-For") 167 170 forwardedPort := req.Header.Get("X-Forwarded-Port") 168 if is Loopback&& forwardedHost != "" && forwardedPort != "" {171 if isProxy && forwardedHost != "" && forwardedPort != "" { 169 172 remoteAddr = net.JoinHostPort(forwardedHost, forwardedPort) 170 173 }
Note:
See TracChangeset
for help on using the changeset viewer.