Browse Source

Merge pull request from GHSA-2hfj-cxw7-g45p

pull/1356/head
Gabe Kangas 5 years ago committed by GitHub
parent
commit
7278ce8f26
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      controllers/index.go
  2. 8
      router/middleware/disableFloc.go
  3. 19
      router/middleware/headers.go

4
controllers/index.go

@ -68,8 +68,8 @@ func IndexHandler(w http.ResponseWriter, r *http.Request) { @@ -68,8 +68,8 @@ func IndexHandler(w http.ResponseWriter, r *http.Request) {
// Set a cache control max-age header
middleware.SetCachingHeaders(w, r)
// Opt-out of Google FLoC
middleware.DisableFloc(w)
// Set our global HTTP headers
middleware.SetHeaders(w)
http.ServeFile(w, r, path.Join(config.WebRoot, r.URL.Path))
}

8
router/middleware/disableFloc.go

@ -1,8 +0,0 @@ @@ -1,8 +0,0 @@
package middleware
import "net/http"
// DisableFloc will tell Google to not use this response in their FLoC tracking.
func DisableFloc(w http.ResponseWriter) {
w.Header().Set("Permissions-Policy", "interest-cohort=()")
}

19
router/middleware/headers.go

@ -0,0 +1,19 @@ @@ -0,0 +1,19 @@
package middleware
import (
"net/http"
"strings"
)
// SetHeaders will set our global headers for web resources.
func SetHeaders(w http.ResponseWriter) {
// Tell Google to not use this response in their FLoC tracking.
w.Header().Set("Permissions-Policy", "interest-cohort=()")
// Content security policy
csp := []string{
"script-src 'self' 'sha256-2HPCfJIJHnY0NrRDPTOdC7AOSJIcQyNxzUuut3TsYRY='",
"worker-src 'self' blob:", // No single quotes around blob:
}
w.Header().Set("Content-Security-Policy", strings.Join(csp, "; "))
}
Loading…
Cancel
Save