Skip to content

Commit

Permalink
Detect App Engine/Flexible Environment cron jobs and avoid HSTS. This…
Browse files Browse the repository at this point in the history
… finally unblocks #35.
  • Loading branch information
lgarron committed Dec 3, 2016
1 parent 644995a commit eae390e
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions hstsserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ func isLocalhost(hostport string) bool {
func hsts(w http.ResponseWriter, r *http.Request) (cont bool) {

switch {
case (r.TLS != nil), maybeAppspotHTTPS(r):
case (r.TLS != nil), maybeAppEngineHTTPS(r):
w.Header().Set("Strict-Transport-Security", "max-age=31536000; includeSubDomains; preload")
return true
case isLocalhost(r.Host):
case isLocalhost(r.Host), maybeAppEngineCron(r):
return true
default:
// The redirect below causes problems with Managed VMs/Flexible Environments.
Expand All @@ -45,6 +45,11 @@ func hsts(w http.ResponseWriter, r *http.Request) (cont bool) {
}

// Note: This can be spoofed when not run on App Engine/Flexible Environment.
func maybeAppspotHTTPS(r *http.Request) bool {
func maybeAppEngineCron(r *http.Request) bool {
return r.Header.Get("X-Appengine-Cron") == "true"
}

// Note: This can be spoofed when not run on App Engine/Flexible Environment.
func maybeAppEngineHTTPS(r *http.Request) bool {
return r.Header.Get("X-Appengine-Https") == "on"
}

0 comments on commit eae390e

Please sign in to comment.