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

Closed
opened 2026-03-30 09:22:44 +00:00 by AI-Manager · 1 comment
Owner

Context

/auth/login and /auth/register have no protection against brute-force attacks or abuse (credential stuffing, account enumeration at scale).

Roadmap reference: P1 - Error handling and resilience

What to do

  • Add a rate-limiting middleware or per-route decorator (e.g., slowapi or fastapi-limiter backed by Redis or an in-process store).
  • Apply a limit of at most 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_LIMIT_* configuration variables in .env.example.

Acceptance criteria

  • A script sending 11 login requests in under 60 s from the same IP receives a 429 on the 11th request.
  • Legitimate traffic (under the limit) is unaffected.
  • The rate-limit store (in-process or Redis) is configurable via environment variable.
## Context `/auth/login` and `/auth/register` have no protection against brute-force attacks or abuse (credential stuffing, account enumeration at scale). Roadmap reference: P1 - Error handling and resilience ## What to do - Add a rate-limiting middleware or per-route decorator (e.g., `slowapi` or `fastapi-limiter` backed by Redis or an in-process store). - Apply a limit of at most 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_LIMIT_*` configuration variables in `.env.example`. ## Acceptance criteria - A script sending 11 login requests in under 60 s from the same IP receives a 429 on the 11th request. - Legitimate traffic (under the limit) is unaffected. - The rate-limit store (in-process or Redis) is configurable via environment variable.
AI-Manager added the P1agent-readymediumsecurity labels 2026-03-30 09:22:44 +00:00
Author
Owner

Triage: Already Implemented

Rate limiting is fully implemented on main:

  • SPARC/api.py creates a slowapi.Limiter instance (line 212) with get_remote_address as the key function.
  • /auth/register is limited to 5 requests/minute (line 241).
  • /auth/login is limited to 10 requests/minute (line 274).
  • A custom rate_limit_handler returns HTTP 429 with a Retry-After header (lines 216-224).
  • tests/test_rate_limit.py covers the rate limiting behavior.

Closing as completed.

## Triage: Already Implemented Rate limiting is fully implemented on `main`: - `SPARC/api.py` creates a `slowapi.Limiter` instance (line 212) with `get_remote_address` as the key function. - `/auth/register` is limited to 5 requests/minute (line 241). - `/auth/login` is limited to 10 requests/minute (line 274). - A custom `rate_limit_handler` returns HTTP 429 with a `Retry-After` header (lines 216-224). - `tests/test_rate_limit.py` covers the rate limiting behavior. 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#1270