fix(backend): rate-limit login and refresh endpoints
/auth/login and /auth/refresh had no throttling, allowing unbounded password brute-force attempts. Add a process-local fixed-window limiter (10 requests/minute per client IP) in front of both. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -2,6 +2,7 @@ package handler
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
@@ -46,8 +47,10 @@ func NewRouter(
|
||||
// -------------------------------------------------------------------------
|
||||
authGroup := v1.Group("/auth")
|
||||
{
|
||||
authGroup.POST("/login", authHandler.Login)
|
||||
authGroup.POST("/refresh", authHandler.Refresh)
|
||||
// Throttle credential endpoints per client IP to slow brute force.
|
||||
authLimiter := newRateLimiter(10, time.Minute).Middleware()
|
||||
authGroup.POST("/login", authLimiter, authHandler.Login)
|
||||
authGroup.POST("/refresh", authLimiter, authHandler.Refresh)
|
||||
|
||||
protected := authGroup.Group("", auth.Handle())
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user