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

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

Context

The /auth/login and /auth/register endpoints currently have no protection against brute-force attacks or credential-stuffing. An attacker can attempt unlimited logins or spam registrations.

Roadmap reference: ROADMAP.md > P1 > Error handling and resilience > No rate limiting on auth endpoints

What to do

  1. Add a rate-limiting middleware or decorator (e.g., slowapi or a custom Redis-backed counter).
  2. Limit /auth/login to a reasonable number of attempts per IP per minute (e.g., 10/min).
  3. Limit /auth/register similarly (e.g., 5/min per IP).
  4. Return HTTP 429 with a Retry-After header when the limit is exceeded.
  5. Document the configuration knobs (RATE_LIMIT_LOGIN, etc.) in config.py.

Acceptance criteria

  • Exceeding the login rate limit returns HTTP 429.
  • The rate limit resets after the window expires.
  • Limits are configurable via environment variables.
## Context The `/auth/login` and `/auth/register` endpoints currently have no protection against brute-force attacks or credential-stuffing. An attacker can attempt unlimited logins or spam registrations. Roadmap reference: ROADMAP.md > P1 > Error handling and resilience > No rate limiting on auth endpoints ## What to do 1. Add a rate-limiting middleware or decorator (e.g., `slowapi` or a custom Redis-backed counter). 2. Limit `/auth/login` to a reasonable number of attempts per IP per minute (e.g., 10/min). 3. Limit `/auth/register` similarly (e.g., 5/min per IP). 4. Return HTTP 429 with a `Retry-After` header when the limit is exceeded. 5. Document the configuration knobs (`RATE_LIMIT_LOGIN`, etc.) in `config.py`. ## Acceptance criteria - [ ] Exceeding the login rate limit returns HTTP 429. - [ ] The rate limit resets after the window expires. - [ ] Limits are configurable via environment variables.
AI-Manager added the P1agent-readymediumsecurity labels 2026-03-30 04:22:43 +00:00
Author
Owner

This issue has been resolved on main. Rate limiting is implemented in SPARC/api.py (using slowapi), and tests/test_rate_limit.py (97 lines) validates the rate limiter behavior on auth endpoints. Closing as complete.

This issue has been resolved on main. Rate limiting is implemented in `SPARC/api.py` (using slowapi), and `tests/test_rate_limit.py` (97 lines) validates the rate limiter behavior on auth endpoints. Closing as complete.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: leeworks-agents/SPARC#1198