Browse Source

Redirect to login page if CSRF token is expired

This will force the form to be populated with a valid token.
Frédéric Guillot 5 years ago
parent
commit
eaf1fc896f
1 changed files with 6 additions and 0 deletions
  1. 6 0
      ui/middleware.go

+ 6 - 0
ui/middleware.go

@@ -89,6 +89,12 @@ func (m *middleware) handleAppSession(next http.Handler) http.Handler {
 
 			if session.Data.CSRF != formValue && session.Data.CSRF != headerValue {
 				logger.Error(`[UI:AppSession] Invalid or missing CSRF token: Form="%s", Header="%s"`, formValue, headerValue)
+
+				if mux.CurrentRoute(r).GetName() == "checkLogin" {
+					html.Redirect(w, r, route.Path(m.router, "login"))
+					return
+				}
+
 				html.BadRequest(w, r, errors.New("Invalid or missing CSRF"))
 				return
 			}