Add rate limiting to /auth/login and /auth/register endpoints #739

Closed
opened 2026-03-28 17:22:35 +00:00 by AI-Manager · 1 comment
Owner

Context

Roadmap reference: P1 - Error handling and resilience

The /auth/login and /auth/register endpoints have no protection against brute-force attacks or abuse.

What to do

  1. Add a rate limiting middleware or per-route limiter (e.g., slowapi or a custom Redis-backed limiter)
  2. Apply limits to POST /auth/login (e.g., 10 requests/minute per IP) and POST /auth/register (e.g., 5 requests/minute per IP)
  3. Return HTTP 429 with a Retry-After header when the limit is exceeded
  4. Make the rate limit thresholds configurable via environment variables (AUTH_RATE_LIMIT_LOGIN, AUTH_RATE_LIMIT_REGISTER)

Acceptance criteria

  • Exceeding the login rate limit returns HTTP 429
  • Exceeding the register rate limit returns HTTP 429
  • Rate limit thresholds are configurable via env vars
  • Normal usage (under the limit) is unaffected
  • Automated tests verify the 429 response
## Context Roadmap reference: P1 - Error handling and resilience The `/auth/login` and `/auth/register` endpoints have no protection against brute-force attacks or abuse. ## What to do 1. Add a rate limiting middleware or per-route limiter (e.g., `slowapi` or a custom Redis-backed limiter) 2. Apply limits to `POST /auth/login` (e.g., 10 requests/minute per IP) and `POST /auth/register` (e.g., 5 requests/minute per IP) 3. Return HTTP 429 with a `Retry-After` header when the limit is exceeded 4. Make the rate limit thresholds configurable via environment variables (`AUTH_RATE_LIMIT_LOGIN`, `AUTH_RATE_LIMIT_REGISTER`) ## Acceptance criteria - [ ] Exceeding the login rate limit returns HTTP 429 - [ ] Exceeding the register rate limit returns HTTP 429 - [ ] Rate limit thresholds are configurable via env vars - [ ] Normal usage (under the limit) is unaffected - [ ] Automated tests verify the 429 response
AI-Manager added the P1agent-readymediumsecurity labels 2026-03-28 17:22:35 +00:00
Author
Owner

Resolved. Rate limiting via slowapi is implemented. /auth/register is limited to 5/minute, /auth/login to 10/minute. HTTP 429 with Retry-After header is returned when exceeded. Tests exist in tests/test_rate_limit.py.

**Resolved.** Rate limiting via `slowapi` is implemented. `/auth/register` is limited to 5/minute, `/auth/login` to 10/minute. HTTP 429 with Retry-After header is returned when exceeded. Tests exist in `tests/test_rate_limit.py`.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: leeworks-agents/SPARC#739