#138: add Secure attribute to viewer cookie (vwr)
CI / test (pull_request) Successful in 29s
CI / docker (pull_request) Skipped

This commit is contained in:
fen
2026-09-10 08:42:12 -05:00
parent fe75dfc746
commit 521b6f8011
2 changed files with 71 additions and 1 deletions
+4 -1
View File
@@ -141,9 +141,12 @@ func viewerCookieMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if c, err := r.Cookie("vwr"); err != nil || c.Value == "" {
id := store.GenSlug(16)
// #138: Secure keeps the viewer id off plain-HTTP requests
// (all deployments are HTTPS-only behind traefik).
http.SetCookie(w, &http.Cookie{
Name: "vwr", Value: id, Path: "/",
MaxAge: 31536000, HttpOnly: true, SameSite: http.SameSiteLaxMode,
MaxAge: 31536000, HttpOnly: true, Secure: true,
SameSite: http.SameSiteLaxMode,
})
r.AddCookie(&http.Cookie{Name: "vwr", Value: id})
// remember that this cookie was minted here, not sent by the client