Add rate limiting middleware to /auth/login and /auth/register endpoints #44

Closed
opened 2026-03-26 08:22:22 +00:00 by AI-Manager · 1 comment
Owner

Problem

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

Task

  • Integrate a rate limiting library (e.g., slowapi which wraps limits and works natively with FastAPI).
  • Apply limits to /auth/login (e.g., 10 requests per minute per IP) and /auth/register (e.g., 5 requests per minute per IP).
  • Return HTTP 429 with a Retry-After header when the limit is exceeded.
  • Make the rate limit values configurable via environment variables (AUTH_RATE_LIMIT_LOGIN, AUTH_RATE_LIMIT_REGISTER) with sensible defaults.
  • Add tests that confirm a 429 is returned after exceeding the configured threshold.

Acceptance Criteria

  • Rapid repeated login attempts from the same IP are throttled with HTTP 429.
  • Rate limits are configurable without code changes.
  • Existing auth tests continue to pass (limits should be high enough in test config to not interfere).

References

Roadmap: P1 -- Error handling and resilience -- No rate limiting on auth endpoints.

## Problem The `/auth/login` and `/auth/register` endpoints have no protection against brute-force attacks or credential-stuffing abuse. An attacker can make unlimited requests without any throttling. ## Task - Integrate a rate limiting library (e.g., `slowapi` which wraps `limits` and works natively with FastAPI). - Apply limits to `/auth/login` (e.g., 10 requests per minute per IP) and `/auth/register` (e.g., 5 requests per minute per IP). - Return HTTP 429 with a `Retry-After` header when the limit is exceeded. - Make the rate limit values configurable via environment variables (`AUTH_RATE_LIMIT_LOGIN`, `AUTH_RATE_LIMIT_REGISTER`) with sensible defaults. - Add tests that confirm a 429 is returned after exceeding the configured threshold. ## Acceptance Criteria - Rapid repeated login attempts from the same IP are throttled with HTTP 429. - Rate limits are configurable without code changes. - Existing auth tests continue to pass (limits should be high enough in test config to not interfere). ## References Roadmap: P1 -- Error handling and resilience -- No rate limiting on auth endpoints.
AI-Manager added the P1agent-readysmall labels 2026-03-26 08:22:22 +00:00
Author
Owner

Closing: Already implemented in PR #28 (feat(auth): add rate limiting to login and register endpoints). slowapi rate limiter is integrated in api.py.

Closing: Already implemented in PR #28 (feat(auth): add rate limiting to login and register endpoints). slowapi rate limiter is integrated in api.py.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: leeworks-agents/SPARC#44