-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
Description
Description
The authentication endpoints currently lack rate limiting protection, making them vulnerable to brute force attacks and potential DoS (Denial of Service) attempts.
Affected Endpoints
-
Password Login
- File:
internal/handler/auth.go - Method:
LoginByPassword
- File:
-
OAuth Login
- File:
internal/handler/auth.go - Method:
LoginByOAuth
- File:
-
OAuth Code URL Generation
- File:
internal/handler/auth.go - Method:
GetOAuthCodeURL
- File:
Security Risks
-
Brute Force Attacks
- Attackers can make unlimited password login attempts
- No cooldown period after failed attempts
-
DoS Vulnerability
- No limit on the number of requests per IP/user
- Could overwhelm the service and Redis/Database
-
Resource Exhaustion
- Each OAuth state generation creates a Redis entry
- Unlimited requests could fill up Redis storage
Suggest solution
- Add Configuration:
[rate_limit]
# Login attempts
login_max_attempts = 5
login_window_minutes = 15
# OAuth requests
oauth_max_requests = 10
oauth_window_minutes = 5
# Per IP limits
ip_max_requests = 100
ip_window_minutes = 1- Apply in Handlers:
func (h *AuthHandler) LoginByPassword(ctx context.Context, req *userpb.LoginByPasswordRequest) (*userpb.LoginSession, error) {
// Rate limit by IP
ip := h.extractIPAddress(ctx)
if err := h.rateLimiter.Limit(ctx,
fmt.Sprintf("rate:ip:%s", ip),
h.config.RateLimit.IPMaxRequests,
time.Duration(h.config.RateLimit.IPWindowMinutes) * time.Minute); err != nil {
return nil, err
}
// Rate limit login attempts by email
if err := h.rateLimiter.Limit(ctx,
fmt.Sprintf("rate:login:%s", req.Email),
h.config.RateLimit.LoginMaxAttempts,
time.Duration(h.config.RateLimit.LoginWindowMinutes) * time.Minute); err != nil {
return nil, err
}
// Existing login logic...
}Implementation Benefits
-
Security Enhancement
- Prevents brute force attacks
- Protects against DoS attempts
- Limits resource consumption
-
Monitoring & Alerts
- Can track rate limit hits
- Alert on suspicious activity
- Identify potential attacks
-
User Experience
- Clear feedback on rate limits
- Prevents account lockouts
- Maintains service stability
Labels
securityenhancementrate-limiting