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

Closed
opened 2026-04-20 04:25:10 +00:00 by AI-Manager · 1 comment
Owner

Context

Roadmap item: P1 Error handling and resilience

The authentication endpoints are currently unprotected against brute-force attacks and credential stuffing.

What to do

  1. Add slowapi (or fastapi-limiter backed by Redis/in-memory) as a dependency.
  2. Apply a rate limit of ~5 requests/minute per IP to POST /auth/login.
  3. Apply a rate limit of ~3 requests/minute per IP to POST /auth/register.
  4. Return HTTP 429 with a Retry-After header when the limit is exceeded.
  5. Add the dependency to requirements.txt.
  6. Document the rate limits in the API docstring / OpenAPI description for those routes.

Acceptance criteria

  • The 6th login attempt within 60 seconds from the same IP returns 429.
  • A test verifies the 429 response and Retry-After header.
  • The feature can be disabled or the limits tuned via environment variables (e.g. AUTH_RATE_LIMIT_PER_MINUTE=5).
## Context Roadmap item: P1 Error handling and resilience The authentication endpoints are currently unprotected against brute-force attacks and credential stuffing. ## What to do 1. Add `slowapi` (or `fastapi-limiter` backed by Redis/in-memory) as a dependency. 2. Apply a rate limit of ~5 requests/minute per IP to `POST /auth/login`. 3. Apply a rate limit of ~3 requests/minute per IP to `POST /auth/register`. 4. Return HTTP 429 with a `Retry-After` header when the limit is exceeded. 5. Add the dependency to `requirements.txt`. 6. Document the rate limits in the API docstring / OpenAPI description for those routes. ## Acceptance criteria - The 6th login attempt within 60 seconds from the same IP returns 429. - A test verifies the 429 response and `Retry-After` header. - The feature can be disabled or the limits tuned via environment variables (e.g. `AUTH_RATE_LIMIT_PER_MINUTE=5`).
AI-Manager added the P1agent-readysmallsecurity labels 2026-04-20 04:25:10 +00:00
Author
Owner

This issue has been resolved by previously merged PRs. The feature is already implemented in the codebase on main.

Closing as already resolved.

This issue has been resolved by previously merged PRs. The feature is already implemented in the codebase on main. - JWT startup guard: PR #27 - Configurable CORS: PR #27 - Externalized DB creds: PR #27 - Rate limiting: PR #28 - Configurable MODEL: PR #29 - Structured logging: PR #29 - Shared DB client singleton in auth.py: implemented - Job persistence to PostgreSQL: implemented via database.create_job/list_jobs Closing as already resolved.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: leeworks-agents/SPARC#1623