From 9b3743e79a9d3de828968c28cb248dbadd8aa2c0 Mon Sep 17 00:00:00 2001 From: Daniel Ponte Date: Mon, 25 Nov 2024 12:57:59 -0500 Subject: [PATCH] Fix cookie weirdness (delete correctly using MaxAge) --- pkg/auth/jwt.go | 5 ++++- pkg/talkgroups/talkgroup.go | 6 +++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/pkg/auth/jwt.go b/pkg/auth/jwt.go index bbd7c14..c725a85 100644 --- a/pkg/auth/jwt.go +++ b/pkg/auth/jwt.go @@ -156,6 +156,7 @@ func (a *Auth) routeRefresh(w http.ResponseWriter, r *http.Request) { cookie := &http.Cookie{ Name: "jwt", Value: tok, + Path: "/", HttpOnly: true, Secure: true, } @@ -216,6 +217,7 @@ func (a *Auth) routeAuth(w http.ResponseWriter, r *http.Request) { cookie := &http.Cookie{ Name: "jwt", Value: tok, + Path: "/", HttpOnly: true, Secure: true, } @@ -242,9 +244,10 @@ func (a *Auth) routeLogout(w http.ResponseWriter, r *http.Request) { cookie := &http.Cookie{ Name: "jwt", Value: "", + Path: "/", HttpOnly: true, Secure: true, - Expires: time.Time{}, + MaxAge: -1, } if a.allowInsecureCookie(r) { diff --git a/pkg/talkgroups/talkgroup.go b/pkg/talkgroups/talkgroup.go index 2a4e7c1..ded46fc 100644 --- a/pkg/talkgroups/talkgroup.go +++ b/pkg/talkgroups/talkgroup.go @@ -43,11 +43,11 @@ var ErrBadTG = errors.New("bad talkgroup format") func (tid *ID) UnmarshalJSON(j []byte) error { // this is a dirty hack since we cannot implement both TextUnmarshaler // and json.Unmarshaler at the same time. sigh. - v := &struct{ - System uint32 `json:"sys"` + v := &struct { + System uint32 `json:"sys"` Talkgroup uint32 `json:"tg"` }{} - + if tid != nil { v.System, v.Talkgroup = tid.System, tid.Talkgroup }