Skip to content

Commit

Permalink
fix bug of cookie split clear
Browse files Browse the repository at this point in the history
  • Loading branch information
Jing-ze committed Aug 19, 2024
1 parent 718b1f3 commit 67d80bb
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions pkg/sessions/cookie/session_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,23 @@ func (s *SessionStore) setSessionCookie(rw http.ResponseWriter, req *http.Reques
if err != nil {
return err
}

var cookieNameRegex = regexp.MustCompile(fmt.Sprintf("^%s(_\\d+)?$", s.Cookie.Name))
cookiesSet := make(map[string]bool)
for _, c := range cookies {
cookiesSet[c.Name] = true
}
for _, c := range req.Cookies() {
if cookieNameRegex.MatchString(c.Name) {
_, exist := cookiesSet[c.Name]
if exist {
continue
}
clearCookie := s.makeCookie(req, c.Name, "", time.Hour*-1, time.Now())
http.SetCookie(rw, clearCookie)
}
}

for _, c := range cookies {
http.SetCookie(rw, c)
}
Expand Down

0 comments on commit 67d80bb

Please sign in to comment.