Skip to content

Commit 7729272

Browse files
findleyrgopherbot
authored andcommitted
share: use forwarded IP for geoIP prefix allow list comparison
CL 556157 used the http.Request.RemoteAddr for comparing with the allow list of miscategorized IP prefixes. This is incorrect as it is generally 127.0.0.1 for App Engine traffic. Use X-Forwarded-For instead: https://cloud.google.com/appengine/docs/standard/reference/request-headers For golang/go#65081 Change-Id: Ia0861bdf76dd401c8fa1cd0871c09ae901f5a089 Reviewed-on: https://go-review.googlesource.com/c/playground/+/556195 TryBot-Result: Gopher Robot <[email protected]> Commit-Queue: Robert Findley <[email protected]> Reviewed-by: Hyang-Ah Hana Kim <[email protected]> Run-TryBot: Robert Findley <[email protected]> Auto-Submit: Robert Findley <[email protected]>
1 parent 46e2687 commit 7729272

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

share.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,11 @@ func allowShare(r *http.Request) bool {
107107
if r.Header.Get("X-AppEngine-Country") != "CN" {
108108
return true
109109
}
110-
for _, prefix := range temporaryAllowListIPPrefixes {
111-
if strings.HasPrefix(r.RemoteAddr, prefix) {
112-
return true
110+
for _, forward := range strings.Split(r.Header.Get("X-Forwarded-For"), ",") {
111+
for _, prefix := range temporaryAllowListIPPrefixes {
112+
if strings.HasPrefix(strings.TrimSpace(forward), prefix) {
113+
return true
114+
}
113115
}
114116
}
115117
return false

0 commit comments

Comments
 (0)