fix(web): start a fresh session at login

SetLoginUser added the user to whatever session the login request
carried, so its CSRF token outlived the login. Anyone can fetch an
anonymous session with its token, and a host on a sibling domain can
plant that cookie in the admin's browser. Clear the session before the
user is stored; the next page load or token fetch mints a new token.
This commit is contained in:
MHSanaei
2026-10-31 09:05:28 +00:00
parent 2e14a2a51a
commit ce532e8df7
2 changed files with 33 additions and 0 deletions
+3
View File
@@ -29,6 +29,9 @@ func SetLoginUser(c *gin.Context, user *model.User) error {
return nil
}
s := sessions.Default(c)
// Anyone can mint the anonymous session this request carried and plant it in a browser,
// so nothing in it, the CSRF token above all, outlives the privilege change.
s.Clear()
s.Set(loginUserKey, user.Id)
s.Set(loginEpochKey, user.LoginEpoch)
return s.Save()