Skip to content

feat(cookie): allow Max-Age to be greater than 30 days - #130

Open
shooma wants to merge 1 commit into
gin-contrib:masterfrom
shooma:infinite-max-age
Open

shooma wants to merge 1 commit into
gin-contrib:masterfrom
shooma:infinite-max-age

Conversation

@shooma

@shooma shooma commented Mar 17, 2021 •

Copy link
Copy Markdown

See: gorilla/sessions#48 (comment)

Now I got [sessions] ERROR! securecookie: expired timestamp after 30 days even if I set store options for a f.e. century

  store := cookie.NewStore([]byte(secret))
  store.Options(gs.Options{
    Path:     "/",
    MaxAge:   60 * 60 * 24 * 365 * 100, // 100 years
    HttpOnly: true,
  })

or if I set MaxAge on cookie itself

session.Set("userID", "user id")
session.Options(sessions.Options{
    MaxAge: 60 * 60 * 24 * 265 * 100,  // 100 years
})
_ = session.Save()

I found same issue on gorilla/sessions, and solution was to explicitly call function MaxAge(int) on CookieStore. But in gin-contrib/sessions this CookieStore struct is hidden under local store:

type store struct {
  *gsessions.CookieStore
}

So I have no way to fix problem on application side.

And I hope this fix will save several hours for someone else.

@shooma

shooma commented Mar 17, 2021

Copy link
Copy Markdown
Author

This solution works only for store.Options (on session storage init) but not work for session.Options (on session init)

@shooma

shooma commented Sep 10, 2021

Copy link
Copy Markdown
Author

Hi guys, is someone alive here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant