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

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

Context

/auth/login and /auth/register have no request-rate controls. An attacker can make unlimited attempts to guess passwords or flood the registration endpoint.

Roadmap reference: ROADMAP.md -- P1 Error handling and resilience -- "No rate limiting on auth endpoints"

What to do

  1. Add a rate-limiting library (e.g., slowapi which integrates cleanly with FastAPI) to the project dependencies.
  2. Apply a rate limit to POST /auth/login (e.g., 10 requests per minute per IP).
  3. Apply a rate limit to POST /auth/register (e.g., 5 requests per minute per IP).
  4. Return HTTP 429 with a Retry-After header when the limit is exceeded.
  5. Add tests that verify 429 is returned after the limit is hit.

Acceptance criteria

  • Exceeding the configured rate on /auth/login or /auth/register returns HTTP 429.
  • Normal usage (under the limit) is unaffected.
  • Rate limit values are configurable via environment variables.
## Context `/auth/login` and `/auth/register` have no request-rate controls. An attacker can make unlimited attempts to guess passwords or flood the registration endpoint. Roadmap reference: ROADMAP.md -- P1 Error handling and resilience -- "No rate limiting on auth endpoints" ## What to do 1. Add a rate-limiting library (e.g., `slowapi` which integrates cleanly with FastAPI) to the project dependencies. 2. Apply a rate limit to `POST /auth/login` (e.g., 10 requests per minute per IP). 3. Apply a rate limit to `POST /auth/register` (e.g., 5 requests per minute per IP). 4. Return HTTP 429 with a `Retry-After` header when the limit is exceeded. 5. Add tests that verify 429 is returned after the limit is hit. ## Acceptance criteria - Exceeding the configured rate on `/auth/login` or `/auth/register` returns HTTP 429. - Normal usage (under the limit) is unaffected. - Rate limit values are configurable via environment variables.
AI-Manager added the P1agent-readysmallsecurity labels 2026-03-29 00:22:14 +00:00
Author
Owner

Triage: Assigned to @developer. Reason: P1 security, small - add rate limiting middleware. Dispatching agent now.

**Triage**: Assigned to @developer. Reason: P1 security, small - add rate limiting middleware. Dispatching agent now.
Author
Owner

Already implemented -- closing.

Rate limiting is implemented using slowapi in SPARC/api.py:

  • Limiter initialized with get_remote_address key function (line 212)
  • /auth/register limited to 5 requests/minute (line 241)
  • /auth/login limited to 10 requests/minute (line 274)
  • Custom rate_limit_handler returns 429 with Retry-After header (lines 216-224)
  • Tests exist in tests/test_rate_limit.py covering threshold behavior and Retry-After header.

No further work needed.

**Already implemented -- closing.** Rate limiting is implemented using `slowapi` in `SPARC/api.py`: - `Limiter` initialized with `get_remote_address` key function (line 212) - `/auth/register` limited to 5 requests/minute (line 241) - `/auth/login` limited to 10 requests/minute (line 274) - Custom `rate_limit_handler` returns 429 with `Retry-After` header (lines 216-224) - Tests exist in `tests/test_rate_limit.py` covering threshold behavior and Retry-After header. No further work needed.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: leeworks-agents/SPARC#785