Skip to content

Commit

Permalink
backend: Make getting requestIP more forgiving
Browse files Browse the repository at this point in the history
We expect that the xff header will be formatted as ip1, ip2 but there
can be situtations where somebody has a xff as ip1,ip2 and our helper
method just ignores this case.
This patch handles the fundamental mistake with getting requestIP.
  • Loading branch information
ashu8912 committed Feb 9, 2021
1 parent dc65fe0 commit 869049c
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions cmd/nebraska/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -826,8 +826,8 @@ func (ctl *controller) processOmahaRequest(c *gin.Context) {
//

func getRequestIP(r *http.Request) string {
ips := strings.Split(r.Header.Get("X-FORWARDED-FOR"), ", ")
if ips[0] != "" && net.ParseIP(ips[0]) != nil {
ips := strings.Split(r.Header.Get("X-FORWARDED-FOR"), ",")
if ips[0] != "" && net.ParseIP(strings.TrimSpace(ips[0])) != nil {
return ips[0]
}
ip, _, _ := net.SplitHostPort(r.RemoteAddr)
Expand Down

0 comments on commit 869049c

Please sign in to comment.