mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-24 03:21:49 +01:00
7ff74a47c8
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: wxiaoguang <wxiaoguang@gmail.com> Co-authored-by: Kyle D <kdumontnu@gmail.com> (cherry picked from commit b18c04ebde94e23d97da4958173faea843d5344f)
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
|
|
}
|