Skip to content

Commit 934cdca

Browse files
broadydmitshur
authored andcommitted
[release-branch.go1.11] cmd/godoc: re-enable host checking, allow test versions
test.golang.org is no longer -- instead allow access to version-specific App Engine URLs (like 20181002t1342-dot-golang-org.appspot.com). App Engine Flex uses the X-Forwarded-Proto to signify the proto used by the originating request (it always uses h1 on 8080 when proxying the request). Updates golang/go#28893 Updates golang/go#27205 Change-Id: I423ffe65df325500a2fa04c7b655797ecc6ad037 Reviewed-on: https://go-review.googlesource.com/c/139237 Reviewed-by: Brad Fitzpatrick <[email protected]> Reviewed-on: https://go-review.googlesource.com/c/150679
1 parent 4dfc99f commit 934cdca

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

cmd/godoc/app.prod.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ env: flex
33

44
env_variables:
55
GODOC_PROD: true
6-
# GODOC_ENFORCE_HOSTS: true # TODO(cbro): modify host filter to allow version-specific URLs (see issue 27205).
6+
GODOC_ENFORCE_HOSTS: true
77
GODOC_REDIS_ADDR: 10.0.0.4:6379 # instance "gophercache"
88
GODOC_ANALYTICS: UA-11222381-2
99
DATASTORE_PROJECT_ID: golang-org

cmd/godoc/handlers.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func (h hostEnforcerHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
4444
h.h.ServeHTTP(w, r)
4545
return
4646
}
47-
if r.TLS == nil || !h.validHost(r.Host) {
47+
if !h.isHTTPS(r) || !h.validHost(r.Host) {
4848
r.URL.Scheme = "https"
4949
if h.validHost(r.Host) {
5050
r.URL.Host = r.Host
@@ -58,9 +58,17 @@ func (h hostEnforcerHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
5858
h.h.ServeHTTP(w, r)
5959
}
6060

61+
func (h hostEnforcerHandler) isHTTPS(r *http.Request) bool {
62+
return r.TLS != nil || r.Header.Get("X-Forwarded-Proto") == "https"
63+
}
64+
6165
func (h hostEnforcerHandler) validHost(host string) bool {
6266
switch strings.ToLower(host) {
63-
case "golang.org", "godoc-test.golang.org", "golang.google.cn":
67+
case "golang.org", "golang.google.cn":
68+
return true
69+
}
70+
if strings.HasSuffix(host, "-dot-golang-org.appspot.com") {
71+
// staging/test
6472
return true
6573
}
6674
return false

0 commit comments

Comments
 (0)