git.iko.soy/typeable/oauth2-proxy
on master help sign in
Make sure the cookie exists before we clear the session in redis
c1ae0caJoel Speed
pkg/sessions/redis/redis_store.go+14−7
@@ -148,13 +148,6 @@ func (store *SessionStore) loadSessionFromString(value string) (*sessions.Sessio
148// Clear clears any saved session information for a given ticket cookie
148// Clear clears any saved session information for a given ticket cookie
149// from redis, and then clears the session
149// from redis, and then clears the session
150func (store *SessionStore) Clear(rw http.ResponseWriter, req *http.Request) error {
150func (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−
158 // We go ahead and clear the cookie first, always.
151 // We go ahead and clear the cookie first, always.
159 clearCookie := store.makeCookie(
152 clearCookie := store.makeCookie(
160 req,
153 req,
@@ -164,6 +157,20 @@ func (store *SessionStore) Clear(rw http.ResponseWriter, req *http.Request) erro
164 )
157 )
165 http.SetCookie(rw, clearCookie)
158 http.SetCookie(rw, clearCookie)
166
159
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+
167 // We only return an error if we had an issue with redis
174 // We only return an error if we had an issue with redis
168 // If there's an issue decoding the ticket, ignore it
175 // If there's an issue decoding the ticket, ignore it
169 ticket, _ := decodeTicket(store.CookieOptions.CookieName, val)
176 ticket, _ := decodeTicket(store.CookieOptions.CookieName, val)