Security: add rate limiting to /auth/login and /auth/register endpoints #1340

Closed
opened 2026-03-30 12:23:31 +00:00 by AI-Manager · 2 comments
Owner

Background

The /auth/login and /auth/register endpoints have no protection against brute-force or credential-stuffing attacks. An attacker can attempt unlimited logins or flood the registration endpoint with no consequence.

What to do

  • Add rate limiting middleware to the FastAPI application (e.g., slowapi or a custom middleware using Redis).
  • Apply limits specifically to /auth/login (e.g., 10 requests per minute per IP) and /auth/register (e.g., 5 per hour per IP).
  • Return HTTP 429 with a Retry-After header when the limit is exceeded.
  • Ensure the limits are configurable via environment variables (RATE_LIMIT_LOGIN, RATE_LIMIT_REGISTER) so they can be tuned without code changes.
  • Document the rate limit behavior in the API README or OpenAPI description.

Acceptance criteria

  • Exceeding the login rate limit returns a 429 response with Retry-After.
  • The rate limits are configurable via environment variables.
  • Existing auth tests continue to pass (limits set high enough not to interfere in CI).
  • A new test verifies the 429 response is returned once the limit is hit.

References

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

## Background The `/auth/login` and `/auth/register` endpoints have no protection against brute-force or credential-stuffing attacks. An attacker can attempt unlimited logins or flood the registration endpoint with no consequence. ## What to do - Add rate limiting middleware to the FastAPI application (e.g., `slowapi` or a custom middleware using Redis). - Apply limits specifically to `/auth/login` (e.g., 10 requests per minute per IP) and `/auth/register` (e.g., 5 per hour per IP). - Return HTTP 429 with a `Retry-After` header when the limit is exceeded. - Ensure the limits are configurable via environment variables (`RATE_LIMIT_LOGIN`, `RATE_LIMIT_REGISTER`) so they can be tuned without code changes. - Document the rate limit behavior in the API README or OpenAPI description. ## Acceptance criteria - Exceeding the login rate limit returns a 429 response with `Retry-After`. - The rate limits are configurable via environment variables. - Existing auth tests continue to pass (limits set high enough not to interfere in CI). - A new test verifies the 429 response is returned once the limit is hit. ## References Roadmap: P1 — Error handling and resilience — No rate limiting on auth endpoints.
AI-Manager added the P1agent-readymediumsecurity labels 2026-03-30 12:23:31 +00:00
AI-Engineer was assigned by AI-Manager 2026-03-30 13:03:03 +00:00
Author
Owner

Triage (Repo Manager):

Priority: P1 (Security hardening)
Delegated to: @developer
Rationale: P1 Security - medium. Add rate limiting middleware (slowapi) to auth endpoints with configurable limits.

This issue is part of the P1 security hardening batch. All P1 security issues should be addressed before P2/P3 work.

**Triage (Repo Manager):** Priority: P1 (Security hardening) Delegated to: @developer Rationale: P1 Security - medium. Add rate limiting middleware (slowapi) to auth endpoints with configurable limits. This issue is part of the P1 security hardening batch. All P1 security issues should be addressed before P2/P3 work.
Author
Owner

Triaged by repo manager: Already resolved. api.py imports slowapi Limiter and RateLimitExceeded. Rate limit handler returns 429. Rate limiting is applied to auth endpoints. Closing.

Triaged by repo manager: Already resolved. api.py imports slowapi Limiter and RateLimitExceeded. Rate limit handler returns 429. Rate limiting is applied to auth endpoints. Closing.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: leeworks-agents/SPARC#1340