Fix session cleanup on error paths

Signed-off-by: Sean Du <do4suki@gmail.com>
This commit is contained in:
2026-07-13 08:03:01 +08:00
parent cb8f587e30
commit 683645be8e
82 changed files with 164 additions and 132 deletions
+8 -3
View File
@@ -29,10 +29,15 @@ func Common(ctx *gin.Context) {
ss := session.Attach(ctx)
ctx.Set("session", ss)
defer ss.FinalizeOrRollback()
if ctx.Request.URL.Path != "/login/authkey" && ctx.Request.URL.Path != "/login/login" {
if ctx.IsAborted() {
return
}
if !honokautils.IsMainLoginEndpoint(ctx.Request.URL.Path) {
if ss.UserPref.ForceRelogin {
honokautils.AbortMaintenanceJSON(ctx, http.StatusNotFound, honokautils.NewNotFoundContent(ctx.Request.URL.String()))
ss.AbortWithStatus(http.StatusNotFound, honokautils.NewNotFoundContent(ctx.Request.URL.Path))
return
}
}
@@ -40,7 +45,7 @@ func Common(ctx *gin.Context) {
authorize := ctx.GetHeader("Authorize")
params, err := url.ParseQuery(authorize)
if err != nil {
honokautils.AbortMaintenanceJSON(ctx, http.StatusNotFound, honokautils.NewNotFoundContent(ctx.Request.URL.String()))
ss.AbortWithStatus(http.StatusNotFound, honokautils.NewNotFoundContent(ctx.Request.URL.Path))
return
}