Skip to content

Commit

Permalink
Fix incorrect cookie path for AppSubURL (go-gitea#29534)
Browse files Browse the repository at this point in the history
Regression of go-gitea#24107
  • Loading branch information
wxiaoguang committed Mar 3, 2024
1 parent cc89625 commit 44398e4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
7 changes: 5 additions & 2 deletions modules/setting/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var SessionConfig = struct {
ProviderConfig string
// Cookie name to save session ID. Default is "MacaronSession".
CookieName string
// Cookie path to store. Default is "/". HINT: there was a bug, the old value doesn't have trailing slash, and could be empty "".
// Cookie path to store. Default is "/".
CookiePath string
// GC interval time in seconds. Default is 3600.
Gclifetime int64
Expand Down Expand Up @@ -49,7 +49,10 @@ func loadSessionFrom(rootCfg ConfigProvider) {
fatalDuplicatedPath("session", SessionConfig.ProviderConfig)
}
SessionConfig.CookieName = sec.Key("COOKIE_NAME").MustString("i_like_gitea")
SessionConfig.CookiePath = AppSubURL + "/" // there was a bug, old code only set CookePath=AppSubURL, no trailing slash
SessionConfig.CookiePath = AppSubURL
if SessionConfig.CookiePath == "" {
SessionConfig.CookiePath = "/"
}
SessionConfig.Secure = sec.Key("COOKIE_SECURE").MustBool(strings.HasPrefix(strings.ToLower(AppURL), "https://"))
SessionConfig.Gclifetime = sec.Key("GC_INTERVAL_TIME").MustInt64(86400)
SessionConfig.Maxlifetime = sec.Key("SESSION_LIFE_TIME").MustInt64(86400)
Expand Down
1 change: 1 addition & 0 deletions routers/common/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func ProtocolMiddlewares() (handlers []any) {
})
})

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

0 comments on commit 44398e4

Please sign in to comment.