Skip to content

Commit 9050ba4

Browse files
committed
gui: fix session persistence bug.
This fixes a bug with session management where a the session middleware does not persis avnewly generated session.
1 parent 64ec712 commit 9050ba4

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

gui/index.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ type indexPageData struct {
2828
// message. The error message will only be displayed if the browser has
2929
// Javascript enabled.
3030
func (ui *GUI) renderIndex(w http.ResponseWriter, r *http.Request, modalError string) {
31-
3231
// Get the 10 most recent confirmed mined blocks.
3332
_, confirmedWork, _ := ui.cache.getConfirmedMinedWork(0, 9)
3433

gui/middleware.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,15 @@ func (ui *GUI) sessionMiddleware(next http.Handler) http.Handler {
3131
// common during development (eg. when using the test harness) but
3232
// it should not occur in production.
3333
if strings.Contains(err.Error(), "securecookie: the value is not valid") {
34-
log.Warnf("getSession error: CSRF secret has changed. Generating new session.")
34+
log.Warn("getSession error: CSRF secret has changed. Generating new session.")
35+
36+
// Persist the generated session.
37+
err = ui.cookieStore.Save(r, w, session)
38+
if err != nil {
39+
log.Errorf("saveSession error: %v", err)
40+
http.Error(w, "Session error", http.StatusInternalServerError)
41+
return
42+
}
3543
} else {
3644
log.Errorf("getSession error: %v", err)
3745
http.Error(w, "Session error", http.StatusInternalServerError)

0 commit comments

Comments
 (0)