Skip to content

Commit

Permalink
Delete legacy cookie before setting new cookie (#31306) (#31317)
Browse files Browse the repository at this point in the history
Backport #31306 by wxiaoguang

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
  • Loading branch information
GiteaBot and wxiaoguang authored Jun 11, 2024
1 parent c1c11aa commit 3fcf865
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions modules/web/middleware/cookie.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ func GetSiteCookie(req *http.Request, name string) string {

// SetSiteCookie returns given cookie value from request header.
func SetSiteCookie(resp http.ResponseWriter, name, value string, maxAge int) {
// Previous versions would use a cookie path with a trailing /.
// These are more specific than cookies without a trailing /, so
// we need to delete these if they exist.
deleteLegacySiteCookie(resp, name)
cookie := &http.Cookie{
Name: name,
Value: url.QueryEscape(value),
Expand All @@ -46,10 +50,6 @@ func SetSiteCookie(resp http.ResponseWriter, name, value string, maxAge int) {
SameSite: setting.SessionConfig.SameSite,
}
resp.Header().Add("Set-Cookie", cookie.String())
// Previous versions would use a cookie path with a trailing /.
// These are more specific than cookies without a trailing /, so
// we need to delete these if they exist.
deleteLegacySiteCookie(resp, name)
}

// deleteLegacySiteCookie deletes the cookie with the given name at the cookie
Expand Down

0 comments on commit 3fcf865

Please # to comment.