Skip to content

Commit 44398e4

Browse files
authored
Fix incorrect cookie path for AppSubURL (#29534)
Regression of #24107
1 parent cc89625 commit 44398e4

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

modules/setting/session.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ var SessionConfig = struct {
2020
ProviderConfig string
2121
// Cookie name to save session ID. Default is "MacaronSession".
2222
CookieName string
23-
// Cookie path to store. Default is "/". HINT: there was a bug, the old value doesn't have trailing slash, and could be empty "".
23+
// Cookie path to store. Default is "/".
2424
CookiePath string
2525
// GC interval time in seconds. Default is 3600.
2626
Gclifetime int64
@@ -49,7 +49,10 @@ func loadSessionFrom(rootCfg ConfigProvider) {
4949
fatalDuplicatedPath("session", SessionConfig.ProviderConfig)
5050
}
5151
SessionConfig.CookieName = sec.Key("COOKIE_NAME").MustString("i_like_gitea")
52-
SessionConfig.CookiePath = AppSubURL + "/" // there was a bug, old code only set CookePath=AppSubURL, no trailing slash
52+
SessionConfig.CookiePath = AppSubURL
53+
if SessionConfig.CookiePath == "" {
54+
SessionConfig.CookiePath = "/"
55+
}
5356
SessionConfig.Secure = sec.Key("COOKIE_SECURE").MustBool(strings.HasPrefix(strings.ToLower(AppURL), "https://"))
5457
SessionConfig.Gclifetime = sec.Key("GC_INTERVAL_TIME").MustInt64(86400)
5558
SessionConfig.Maxlifetime = sec.Key("SESSION_LIFE_TIME").MustInt64(86400)

routers/common/middleware.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ func ProtocolMiddlewares() (handlers []any) {
3838
})
3939
})
4040

41+
// wrap the request and response, use the process context and add it to the process manager
4142
handlers = append(handlers, func(next http.Handler) http.Handler {
4243
return http.HandlerFunc(func(resp http.ResponseWriter, req *http.Request) {
4344
ctx, _, finished := process.GetManager().AddTypedContext(req.Context(), fmt.Sprintf("%s: %s", req.Method, req.RequestURI), process.RequestProcessType, true)

0 commit comments

Comments
 (0)