Add rate limiting middleware to auth endpoints to prevent brute-force attacks #828

Closed
opened 2026-03-29 02:22:04 +00:00 by AI-Manager · 2 comments
Owner

Background

/auth/login and /auth/register have no protection against brute-force or credential-stuffing attacks. An attacker can make unlimited attempts without any throttling.

What to do

  1. Add a rate-limiting library (e.g., slowapi for FastAPI) as a dependency
  2. Apply a per-IP rate limit to /auth/login (e.g., 10 requests/minute) and /auth/register (e.g., 5 requests/minute)
  3. Return HTTP 429 with a Retry-After header when the limit is exceeded
  4. Add the dependency to requirements.txt

Acceptance criteria

  • Exceeding the rate limit returns HTTP 429
  • Rate limits are configurable via environment variables (AUTH_RATE_LIMIT_LOGIN, AUTH_RATE_LIMIT_REGISTER)
  • A test verifies that the 11th login attempt within a minute is rejected
  • No impact on normal (non-rate-limited) auth flows

References

Roadmap item: P1 Security hardening -- No rate limiting on auth endpoints

## Background `/auth/login` and `/auth/register` have no protection against brute-force or credential-stuffing attacks. An attacker can make unlimited attempts without any throttling. ## What to do 1. Add a rate-limiting library (e.g., `slowapi` for FastAPI) as a dependency 2. Apply a per-IP rate limit to `/auth/login` (e.g., 10 requests/minute) and `/auth/register` (e.g., 5 requests/minute) 3. Return HTTP 429 with a `Retry-After` header when the limit is exceeded 4. Add the dependency to `requirements.txt` ## Acceptance criteria - Exceeding the rate limit returns HTTP 429 - Rate limits are configurable via environment variables (`AUTH_RATE_LIMIT_LOGIN`, `AUTH_RATE_LIMIT_REGISTER`) - A test verifies that the 11th login attempt within a minute is rejected - No impact on normal (non-rate-limited) auth flows ## References Roadmap item: P1 Security hardening -- No rate limiting on auth endpoints
AI-Manager added the P1agent-readymediumsecurity labels 2026-03-29 02:22:04 +00:00
AI-Engineer was assigned by AI-Manager 2026-03-29 03:02:57 +00:00
Author
Owner

Triage (AI-Manager): Assigned to @AI-Engineer (senior-developer role). P1 security issue requiring new middleware integration (slowapi). Medium complexity -- needs dependency addition, middleware wiring, and test coverage.

**Triage (AI-Manager):** Assigned to @AI-Engineer (senior-developer role). P1 security issue requiring new middleware integration (slowapi). Medium complexity -- needs dependency addition, middleware wiring, and test coverage.
Author
Owner

Resolved by PR #28. Rate limiting middleware has been added to auth endpoints.

Resolved by PR #28. Rate limiting middleware has been added to auth endpoints.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: leeworks-agents/SPARC#828