mirror of
https://github.com/go-gitea/gitea
synced 2024-11-14 05:51:33 +01:00
222d16e6ea
Backport #30375 by @jtran Cookies may exist on "/subpath" and "/subpath/" for some legacy reasons (eg: changed CookiePath behavior in code). The legacy cookie should be removed correctly. Co-authored-by: Jonathan Tran <jonnytran@gmail.com> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com> Co-authored-by: Kyle D <kdumontnu@gmail.com>
30 lines
790 B
Go
30 lines
790 B
Go
// Copyright 2020 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package session
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"code.gitea.io/gitea/modules/setting"
|
|
"code.gitea.io/gitea/modules/web/middleware"
|
|
|
|
"gitea.com/go-chi/session"
|
|
)
|
|
|
|
// Store represents a session store
|
|
type Store interface {
|
|
Get(any) any
|
|
Set(any, any) error
|
|
Delete(any) error
|
|
}
|
|
|
|
// RegenerateSession regenerates the underlying session and returns the new store
|
|
func RegenerateSession(resp http.ResponseWriter, req *http.Request) (Store, error) {
|
|
// Ensure that a cookie with a trailing slash does not take precedence over
|
|
// the cookie written by the middleware.
|
|
middleware.DeleteLegacySiteCookie(resp, setting.SessionConfig.CookieName)
|
|
|
|
s, err := session.RegenerateSession(resp, req)
|
|
return s, err
|
|
}
|