Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix to delete cookie when AppSubURL is non-empty #30375

Merged
merged 20 commits into from Apr 14, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 18 additions & 2 deletions modules/web/middleware/cookie.go
Expand Up @@ -48,7 +48,23 @@ func SetSiteCookie(resp http.ResponseWriter, name, value string, maxAge int) {
if maxAge < 0 {
// There was a bug in "setting.SessionConfig.CookiePath" code, the old default value of it was empty "".
// So we have to delete the cookie on path="" again, because some old code leaves cookies on path="".
cookie.Path = strings.TrimSuffix(setting.SessionConfig.CookiePath, "/")
resp.Header().Add("Set-Cookie", cookie.String())
// The code was updated, but it behaves differently depending on the
// value of AppSubURL. When AppSubURL is non-empty, the cookie with a
// trailing slash must be deleted.
withoutTrailingSlash := strings.TrimSuffix(setting.SessionConfig.CookiePath, "/")
withTrailingSlash := ensureSuffix(setting.SessionConfig.CookiePath, "/")
jtran marked this conversation as resolved.
Show resolved Hide resolved
for _, path := range []string{withoutTrailingSlash, withTrailingSlash} {
if setting.SessionConfig.CookiePath != path {
cookie.Path = path
resp.Header().Add("Set-Cookie", cookie.String())
}
wxiaoguang marked this conversation as resolved.
Show resolved Hide resolved
}
}
}

func ensureSuffix(s, suffix string) string {
if strings.HasSuffix(s, suffix) {
return s
}
return s + suffix
}
jtran marked this conversation as resolved.
Show resolved Hide resolved