git.iko.soy/typeable/oauth2-proxy
on master help sign in
Make sure the cookie exists before we clear the session in redis

(cherry picked from commit 6d7f0ab57d554706425f76aed4df60717dd63ece)

commitc1ae0ca807818b4bfdf7a49e59e064bafc05618c authorJoel Speed <Joel.speed@hotmail.co.uk> dateThu 30 May 2019, 10:53 (7 years ago) parent22199fa
1 file changed+14−7
pkg/sessions/redis/redis_store.go+14−7
pkg/sessions/redis/redis_store.go+14−7
@@ -148,13 +148,6 @@ func (store *SessionStore) loadSessionFromString(value string) (*sessions.Sessio
148148// Clear clears any saved session information for a given ticket cookie
149149// from redis, and then clears the session
150150func (store *SessionStore) Clear(rw http.ResponseWriter, req *http.Request) error {
151− requestCookie, _ := req.Cookie(store.CookieOptions.CookieName)
152−
153− val, _, ok := cookie.Validate(requestCookie, store.CookieOptions.CookieSecret, store.CookieOptions.CookieExpire)
154− if !ok {
155− return fmt.Errorf("Cookie Signature not valid")
156− }
157−
158151 // We go ahead and clear the cookie first, always.
159152 clearCookie := store.makeCookie(
160153 req,
@@ -164,6 +157,20 @@ func (store *SessionStore) Clear(rw http.ResponseWriter, req *http.Request) erro
164157 )
165158 http.SetCookie(rw, clearCookie)
166159
160+ // If there was an existing cookie we should clear the session in redis
161+ requestCookie, err := req.Cookie(store.CookieOptions.CookieName)
162+ if err != nil && err == http.ErrNoCookie {
163+ // No existing cookie so can't clear redis
164+ return nil
165+ } else if err != nil {
166+ return fmt.Errorf("error retrieving cookie: %v", err)
167+ }
168+
169+ val, _, ok := cookie.Validate(requestCookie, store.CookieOptions.CookieSecret, store.CookieOptions.CookieExpire)
170+ if !ok {
171+ return fmt.Errorf("Cookie Signature not valid")
172+ }
173+
167174 // We only return an error if we had an issue with redis
168175 // If there's an issue decoding the ticket, ignore it
169176 ticket, _ := decodeTicket(store.CookieOptions.CookieName, val)