Skip to content

Commit 3fcf865

Browse files
GiteaBotwxiaoguang
andauthored
Delete legacy cookie before setting new cookie (go-gitea#31306) (go-gitea#31317)
Backport go-gitea#31306 by wxiaoguang Co-authored-by: wxiaoguang <[email protected]>
1 parent c1c11aa commit 3fcf865

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

modules/web/middleware/cookie.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ func GetSiteCookie(req *http.Request, name string) string {
3535

3636
// SetSiteCookie returns given cookie value from request header.
3737
func SetSiteCookie(resp http.ResponseWriter, name, value string, maxAge int) {
38+
// Previous versions would use a cookie path with a trailing /.
39+
// These are more specific than cookies without a trailing /, so
40+
// we need to delete these if they exist.
41+
deleteLegacySiteCookie(resp, name)
3842
cookie := &http.Cookie{
3943
Name: name,
4044
Value: url.QueryEscape(value),
@@ -46,10 +50,6 @@ func SetSiteCookie(resp http.ResponseWriter, name, value string, maxAge int) {
4650
SameSite: setting.SessionConfig.SameSite,
4751
}
4852
resp.Header().Add("Set-Cookie", cookie.String())
49-
// Previous versions would use a cookie path with a trailing /.
50-
// These are more specific than cookies without a trailing /, so
51-
// we need to delete these if they exist.
52-
deleteLegacySiteCookie(resp, name)
5353
}
5454

5555
// deleteLegacySiteCookie deletes the cookie with the given name at the cookie

0 commit comments

Comments
 (0)