From d77b0d2062b27965b5127a196714c123ba27f956 Mon Sep 17 00:00:00 2001 From: Mark Youngman Date: Wed, 3 Jul 2024 13:29:07 +0100 Subject: [PATCH 1/2] Add MaxLength --- sqlitestore.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/sqlitestore.go b/sqlitestore.go index 46e015c..8aa563a 100644 --- a/sqlitestore.go +++ b/sqlitestore.go @@ -281,3 +281,11 @@ func (m *SqliteStore) load(session *sessions.Session) error { return nil } + +func (m *SqliteStore) MaxLength(l int) { + for _, c := range m.Codecs { + if codec, ok := c.(*securecookie.SecureCookie); ok { + codec.MaxLength(l) + } + } +} From 4e4ca167376838961d92ce5624cb3f00e02f566e Mon Sep 17 00:00:00 2001 From: Mark Youngman Date: Wed, 3 Jul 2024 13:34:15 +0100 Subject: [PATCH 2/2] Fix staticcheck warnings --- sqlitestore.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sqlitestore.go b/sqlitestore.go index 8aa563a..dcbb08c 100644 --- a/sqlitestore.go +++ b/sqlitestore.go @@ -223,7 +223,7 @@ func (m *SqliteStore) Delete(r *http.Request, w http.ResponseWriter, session *se } func (m *SqliteStore) save(session *sessions.Session) error { - if session.IsNew == true { + if session.IsNew { return m.insert(session) } var createdOn time.Time @@ -267,9 +267,9 @@ func (m *SqliteStore) load(session *sessions.Session) error { if scanErr != nil { return scanErr } - if sess.expiresOn.Sub(time.Now()) < 0 { + if time.Until(sess.expiresOn) < 0 { log.Printf("Session expired on %s, but it is %s now.", sess.expiresOn, time.Now()) - return errors.New("Session expired") + return errors.New("session expired") } err := securecookie.DecodeMulti(session.Name(), sess.data, &session.Values, m.Codecs...) if err != nil {