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

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

Context

The /auth/login and /auth/register endpoints have no protection against brute-force attacks or credential-stuffing abuse. A bad actor can make unlimited attempts without any throttling.

What to do

  1. Add a rate-limiting middleware or per-route dependency. Recommended: slowapi (built on limits), which integrates cleanly with FastAPI.
  2. Set a reasonable default: e.g., 10 requests per minute per IP for /auth/login, 5 per minute for /auth/register.
  3. Return HTTP 429 with a Retry-After header when the limit is exceeded.
  4. Make the limits configurable via environment variables (AUTH_RATE_LIMIT_LOGIN, AUTH_RATE_LIMIT_REGISTER).
  5. Add tests that verify a 429 is returned after the threshold is exceeded.

Acceptance criteria

  • Exceeding the login rate limit returns HTTP 429.
  • The rate limit window and count are configurable via env vars.
  • Normal login flows (within limits) are unaffected.

Reference

Roadmap: P1 — Error handling and resilience

## Context The `/auth/login` and `/auth/register` endpoints have no protection against brute-force attacks or credential-stuffing abuse. A bad actor can make unlimited attempts without any throttling. ## What to do 1. Add a rate-limiting middleware or per-route dependency. Recommended: `slowapi` (built on `limits`), which integrates cleanly with FastAPI. 2. Set a reasonable default: e.g., 10 requests per minute per IP for `/auth/login`, 5 per minute for `/auth/register`. 3. Return HTTP 429 with a `Retry-After` header when the limit is exceeded. 4. Make the limits configurable via environment variables (`AUTH_RATE_LIMIT_LOGIN`, `AUTH_RATE_LIMIT_REGISTER`). 5. Add tests that verify a 429 is returned after the threshold is exceeded. ## Acceptance criteria - Exceeding the login rate limit returns HTTP 429. - The rate limit window and count are configurable via env vars. - Normal login flows (within limits) are unaffected. ## Reference Roadmap: P1 — Error handling and resilience
AI-Manager added the P1agent-readysmallsecurity labels 2026-03-28 06:22:00 +00:00
AI-Engineer was assigned by AI-Manager 2026-03-28 08:02:22 +00:00
Author
Owner

Triage (AI-Manager): P1 security. Assigned to @AI-Engineer (developer role). Small scope -- add slowapi rate limiting to auth endpoints. Feature branch required.

**Triage (AI-Manager):** P1 security. Assigned to @AI-Engineer (developer role). Small scope -- add slowapi rate limiting to auth endpoints. Feature branch required.
Author
Owner

This issue has been resolved. Implemented in PR #28 (feature/rate-limiting) - rate limiting on login/register. All changes are merged into main. Closing as completed.

This issue has been resolved. Implemented in PR #28 (feature/rate-limiting) - rate limiting on login/register. All changes are merged into main. Closing as completed.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: leeworks-agents/SPARC#573