Merge pull request #26 from lukaszraczylo/additional-improvements

Cleanup old cookies properly.
This commit is contained in:
2025-01-21 17:34:16 +00:00
committed by GitHub
+15 -5
View File
@@ -26,11 +26,11 @@ func generateSecureRandomString(length int) string {
} }
// Cookie names and configuration constants used for session management // Cookie names and configuration constants used for session management
var ( const (
// Using random prefixes to make cookie names less predictable // Using fixed prefixes for consistent cookie naming across restarts
mainCookieName = "_oidc_raczylo_m_" + generateSecureRandomString(8) mainCookieName = "_oidc_raczylo_m"
accessTokenCookie = "_oidc_raczylo_a_" + generateSecureRandomString(8) accessTokenCookie = "_oidc_raczylo_a"
refreshTokenCookie = "_oidc_raczylo_r_" + generateSecureRandomString(8) refreshTokenCookie = "_oidc_raczylo_r"
) )
const ( const (
@@ -435,6 +435,11 @@ func (sd *SessionData) expireAccessTokenChunks(w http.ResponseWriter) {
} }
func (sd *SessionData) SetAccessToken(token string) { func (sd *SessionData) SetAccessToken(token string) {
// Expire any existing chunk cookies first
if sd.request != nil {
sd.expireAccessTokenChunks(nil) // Will be saved when Save() is called
}
// Clear and prepare chunks map for new token // Clear and prepare chunks map for new token
sd.accessTokenChunks = make(map[int]*sessions.Session) sd.accessTokenChunks = make(map[int]*sessions.Session)
@@ -519,6 +524,11 @@ func (sd *SessionData) expireRefreshTokenChunks(w http.ResponseWriter) {
} }
func (sd *SessionData) SetRefreshToken(token string) { func (sd *SessionData) SetRefreshToken(token string) {
// Expire any existing chunk cookies first
if sd.request != nil {
sd.expireRefreshTokenChunks(nil) // Will be saved when Save() is called
}
// Clear and prepare chunks map for new token // Clear and prepare chunks map for new token
sd.refreshTokenChunks = make(map[int]*sessions.Session) sd.refreshTokenChunks = make(map[int]*sessions.Session)