Files
mce/internal/middleware/rate.go
Victor_Jay 7fdea90ded feat: 敏感操作增加IP维度限流
- RateLimiter 新增 AllowSensitive 方法(1分钟5次,超限封禁5分钟)
- 新增 SensitiveRateLimit Gin 中间件
- 改密(PUT /api/settings/password)增加限流保护
- 注销(POST /api/settings/delete-account)增加限流保护
- 签到(POST /api/level/checkin)增加限流保护
2026-06-02 19:03:04 +08:00

25 lines
524 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package middleware
import (
"net/http"
"github.com/gin-gonic/gin"
)
// SensitiveRateLimit 敏感操作(改密/注销/签到IP 维度限流中间件。
// 1 分钟最多 5 次请求,超限后封禁 5 分钟。
func SensitiveRateLimit(rl *RateLimiter) gin.HandlerFunc {
return func(c *gin.Context) {
result := rl.AllowSensitive(c.ClientIP())
if result.Blocked {
c.JSON(http.StatusTooManyRequests, gin.H{
"success": false,
"error": result.Message,
})
c.Abort()
return
}
c.Next()
}
}