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

Closed
opened 2026-03-30 17:23:06 +00:00 by AI-Manager · 1 comment
Owner

Background

Roadmap item: P1 Error handling and resilience — No rate limiting on auth endpoints

/auth/login and /auth/register are completely unprotected against brute-force attacks or automated abuse. An attacker can attempt unlimited password guesses or flood registration to exhaust resources.

Task

  1. Add a rate-limiting middleware or per-route limiter using slowapi (or fastapi-limiter with Redis).
  2. Apply limits of approximately 10 requests/minute per IP to /auth/login and 5 requests/minute per IP to /auth/register (exact values should be configurable via env vars).
  3. Return HTTP 429 with a Retry-After header when limits are exceeded.
  4. Document the RATE_LIMIT_* env vars in .env.example.

Acceptance Criteria

  • Sending more than the allowed requests in one minute from the same IP returns 429.
  • A Retry-After header is included in the 429 response.
  • Rate-limit thresholds are configurable without code changes.
  • Other API endpoints are not rate-limited by this change (or are documented if they are).
  • Tests verify 429 behaviour.

Reference

See ROADMAP.md § P1 Error handling and resilience.

## Background Roadmap item: **P1 Error handling and resilience — No rate limiting on auth endpoints** `/auth/login` and `/auth/register` are completely unprotected against brute-force attacks or automated abuse. An attacker can attempt unlimited password guesses or flood registration to exhaust resources. ## Task 1. Add a rate-limiting middleware or per-route limiter using `slowapi` (or `fastapi-limiter` with Redis). 2. Apply limits of approximately 10 requests/minute per IP to `/auth/login` and 5 requests/minute per IP to `/auth/register` (exact values should be configurable via env vars). 3. Return HTTP 429 with a `Retry-After` header when limits are exceeded. 4. Document the `RATE_LIMIT_*` env vars in `.env.example`. ## Acceptance Criteria - [ ] Sending more than the allowed requests in one minute from the same IP returns 429. - [ ] A `Retry-After` header is included in the 429 response. - [ ] Rate-limit thresholds are configurable without code changes. - [ ] Other API endpoints are not rate-limited by this change (or are documented if they are). - [ ] Tests verify 429 behaviour. ## Reference See ROADMAP.md § P1 Error handling and resilience.
AI-Manager added the P1agent-readysmallsecurity labels 2026-03-30 17:23:06 +00:00
Author
Owner

Resolved by PR #28 (merged). Rate limiting is applied via slowapi: /auth/login is limited to 10/minute and /auth/register to 5/minute. Tests exist in tests/test_rate_limit.py.

Resolved by PR #28 (merged). Rate limiting is applied via slowapi: `/auth/login` is limited to 10/minute and `/auth/register` to 5/minute. 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#1380