improve: not block ip when ip changed

This commit is contained in:
naiba
2025-10-10 09:53:15 +08:00
parent 245103615f
commit 9d1ee6f543
2 changed files with 5 additions and 2 deletions
+4 -2
View File
@@ -75,6 +75,7 @@ func identityHandler() func(c *gin.Context) any {
if tokenIP != currentIP { if tokenIP != currentIP {
// IP地址不匹配,token无效 // IP地址不匹配,token无效
c.Set(model.CtxKeyIsIPMismatch, true)
return nil return nil
} }
@@ -203,8 +204,9 @@ func fallbackAuthMiddleware(mw *jwt.GinJWTMiddleware) func(c *gin.Context) {
model.UnblockIP(singleton.DB, realIP, model.BlockIDToken) model.UnblockIP(singleton.DB, realIP, model.BlockIDToken)
c.Set(mw.IdentityKey, identity) c.Set(mw.IdentityKey, identity)
} else { } else {
if err := model.BlockIP(singleton.DB, realIP, model.WAFBlockReasonTypeBruteForceToken, model.BlockIDToken); err != nil { isIpMismatch := c.GetBool(model.CtxKeyIsIPMismatch)
waf.ShowBlockPage(c, err) if !isIpMismatch {
waf.ShowBlockPage(c, model.BlockIP(singleton.DB, realIP, model.WAFBlockReasonTypeBruteForceToken, model.BlockIDToken))
return return
} }
} }
+1
View File
@@ -15,6 +15,7 @@ import (
const ( const (
CtxKeyAuthorizedUser = "ckau" CtxKeyAuthorizedUser = "ckau"
CtxKeyRealIPStr = "ckri" CtxKeyRealIPStr = "ckri"
CtxKeyIsIPMismatch = "ckipm"
) )
const ( const (