From 8287484cc6bb4eaeacdf8ddcb74e2d0d7611e846 Mon Sep 17 00:00:00 2001 From: Gabe Kangas Date: Thu, 15 Apr 2021 22:17:52 -0700 Subject: [PATCH] Add Google FLoC opt-out header on web page requests. Closes #939 --- controllers/index.go | 3 +++ router/middleware/disableFloc.go | 8 ++++++++ 2 files changed, 11 insertions(+) create mode 100644 router/middleware/disableFloc.go diff --git a/controllers/index.go b/controllers/index.go index 06b68d27d..46f682d78 100644 --- a/controllers/index.go +++ b/controllers/index.go @@ -64,6 +64,9 @@ 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) + http.ServeFile(w, r, path.Join(config.WebRoot, r.URL.Path)) } diff --git a/router/middleware/disableFloc.go b/router/middleware/disableFloc.go new file mode 100644 index 000000000..9f6787dec --- /dev/null +++ b/router/middleware/disableFloc.go @@ -0,0 +1,8 @@ +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=()") +}