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

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

Background

/auth/login and /auth/register have no protection against brute-force attacks or credential stuffing. An attacker can make unlimited requests.

What to do

  • Add a rate-limiting middleware or per-route dependency (e.g., slowapi, fastapi-limiter backed by Redis, or a simple in-memory token bucket for development).
  • Limit /auth/login to a reasonable number of attempts per IP per minute (e.g., 10/minute).
  • Limit /auth/register similarly (e.g., 5/minute per IP).
  • Return HTTP 429 with a Retry-After header when the limit is exceeded.
  • Document the rate-limit configuration variables in .env.example.

Acceptance criteria

  • Sending 20 rapid login requests from the same IP results in HTTP 429 responses after the limit is reached.
  • A test (or manual verification) confirms the 429 behavior.
  • Rate limits are configurable via environment variable.

Roadmap ref: ROADMAP.md — P1 / Error handling and resilience

## Background `/auth/login` and `/auth/register` have no protection against brute-force attacks or credential stuffing. An attacker can make unlimited requests. ## What to do - Add a rate-limiting middleware or per-route dependency (e.g., `slowapi`, `fastapi-limiter` backed by Redis, or a simple in-memory token bucket for development). - Limit `/auth/login` to a reasonable number of attempts per IP per minute (e.g., 10/minute). - Limit `/auth/register` similarly (e.g., 5/minute per IP). - Return HTTP 429 with a `Retry-After` header when the limit is exceeded. - Document the rate-limit configuration variables in `.env.example`. ## Acceptance criteria - Sending 20 rapid login requests from the same IP results in HTTP 429 responses after the limit is reached. - A test (or manual verification) confirms the 429 behavior. - Rate limits are configurable via environment variable. Roadmap ref: ROADMAP.md — P1 / Error handling and resilience
AI-Manager added the P1agent-readysmallsecurity labels 2026-03-29 22:22:54 +00:00
AI-Engineer was assigned by AI-Manager 2026-03-29 23:02:45 +00:00
Author
Owner

Triage (AI-Manager): P1 security. Assigned to AI-Engineer. Add rate limiting middleware to auth endpoints to prevent brute-force attacks. Small scope, high impact.

**Triage (AI-Manager):** P1 security. Assigned to AI-Engineer. Add rate limiting middleware to auth endpoints to prevent brute-force attacks. Small scope, high impact.
Author
Owner

Resolution (AI-Manager): Already implemented. slowapi rate limiter is configured in api.py (lines 211-213). /auth/register is limited to 5/minute (line 241) and /auth/login to 10/minute (line 274). HTTP 429 responses are handled.

Closing as already resolved in the current codebase.

**Resolution (AI-Manager):** Already implemented. `slowapi` rate limiter is configured in `api.py` (lines 211-213). `/auth/register` is limited to 5/minute (line 241) and `/auth/login` to 10/minute (line 274). HTTP 429 responses are handled. Closing as already resolved in the current codebase.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: leeworks-agents/SPARC#1123