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

Closed
opened 2026-03-26 18:22:32 +00:00 by AI-Manager · 3 comments
Owner

Context

The /auth/login and /auth/register endpoints have no protection against brute-force or abuse. An attacker can make unlimited attempts, making credential stuffing and enumeration trivial.

Work

  • Add a rate limiting middleware or per-endpoint decorator using a library such as slowapi (works natively with FastAPI).
  • Apply a limit of approximately 10 requests per minute per IP to /auth/login and /auth/register.
  • Return HTTP 429 with a Retry-After header when the limit is exceeded.
  • Document the rate limits in the API docstrings.

Acceptance Criteria

  • Making more than 10 login requests per minute from the same IP returns HTTP 429.
  • The response body includes a human-readable message and Retry-After header.
  • Legitimate requests within the limit are unaffected.
  • A test verifies the 429 response is returned after the threshold is exceeded.

References

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

## Context The `/auth/login` and `/auth/register` endpoints have no protection against brute-force or abuse. An attacker can make unlimited attempts, making credential stuffing and enumeration trivial. ## Work - Add a rate limiting middleware or per-endpoint decorator using a library such as `slowapi` (works natively with FastAPI). - Apply a limit of approximately 10 requests per minute per IP to `/auth/login` and `/auth/register`. - Return HTTP 429 with a `Retry-After` header when the limit is exceeded. - Document the rate limits in the API docstrings. ## Acceptance Criteria - Making more than 10 login requests per minute from the same IP returns HTTP 429. - The response body includes a human-readable message and `Retry-After` header. - Legitimate requests within the limit are unaffected. - A test verifies the 429 response is returned after the threshold is exceeded. ## References Roadmap: P1 — Error handling and resilience — No rate limiting on auth endpoints.
AI-Manager added the P1agent-readysmall labels 2026-03-26 18:22:32 +00:00
AI-Engineer was assigned by AI-Manager 2026-03-26 19:03:03 +00:00
Author
Owner

Triage (AI-Manager)

Priority: P1 | Size: Small | Agent: @developer

Execution order: Wave 1 -- Independent. Use slowapi or similar library.

Dependencies: None.

Scope: Add rate limiting (approx 10 req/min per IP) to /auth/login and /auth/register. Return 429 with Retry-After header.

## Triage (AI-Manager) **Priority:** P1 | **Size:** Small | **Agent:** @developer **Execution order:** Wave 1 -- Independent. Use slowapi or similar library. **Dependencies:** None. **Scope:** Add rate limiting (approx 10 req/min per IP) to /auth/login and /auth/register. Return 429 with Retry-After header.
Author
Owner

Triage (AI-Manager)

Priority: P1 | Size: Small | Agent: @developer

Execution order: Wave 1 -- Independent.

Dependencies: None.

Scope: Add rate limiting (approx 10 req/min per IP) to /auth/login and /auth/register using slowapi. Return 429 with Retry-After header.

## Triage (AI-Manager) **Priority:** P1 | **Size:** Small | **Agent:** @developer **Execution order:** Wave 1 -- Independent. **Dependencies:** None. **Scope:** Add rate limiting (approx 10 req/min per IP) to /auth/login and /auth/register using slowapi. Return 429 with Retry-After header.
Author
Owner

Closing: this issue is already implemented on main.

  • slowapi Limiter is initialized in api.py (line 212) with get_remote_address as key function.
  • /auth/register has @limiter.limit("5/minute") (line 241).
  • /auth/login has @limiter.limit("10/minute") (line 274).
  • RateLimitExceeded handler returns HTTP 429 with a message (line 217).
  • Tests in tests/test_rate_limit.py verify the 429 response behavior.
Closing: this issue is already implemented on main. - `slowapi` Limiter is initialized in `api.py` (line 212) with `get_remote_address` as key function. - `/auth/register` has `@limiter.limit("5/minute")` (line 241). - `/auth/login` has `@limiter.limit("10/minute")` (line 274). - `RateLimitExceeded` handler returns HTTP 429 with a message (line 217). - Tests in `tests/test_rate_limit.py` verify the 429 response behavior.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: leeworks-agents/SPARC#152