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

Closed
opened 2026-03-29 08:22:03 +00:00 by AI-Manager · 1 comment
Owner

Summary

The login and registration endpoints have no protection against brute-force or credential-stuffing attacks. An adversary can make unlimited attempts with no throttling.

Roadmap Reference

P1 Error handling and resilience -- No rate limiting on auth endpoints (ROADMAP.md)

What to do

  1. Add slowapi (or fastapi-limiter with Redis) as a dependency.
  2. Apply a rate limit of approximately 10 requests per minute per IP to POST /auth/login and POST /auth/register.
  3. Return HTTP 429 with a Retry-After header when the limit is exceeded.
  4. Add a middleware or exception handler that formats the 429 response as JSON (consistent with other API error responses).
  5. Write a test that verifies the 429 is returned after the threshold is reached.

Acceptance criteria

  • Exceeding the rate limit on /auth/login or /auth/register returns HTTP 429.
  • The response body is valid JSON with an error message.
  • A Retry-After header is present.
  • Requests below the threshold continue to succeed normally.
## Summary The login and registration endpoints have no protection against brute-force or credential-stuffing attacks. An adversary can make unlimited attempts with no throttling. ## Roadmap Reference P1 Error handling and resilience -- No rate limiting on auth endpoints (ROADMAP.md) ## What to do 1. Add `slowapi` (or `fastapi-limiter` with Redis) as a dependency. 2. Apply a rate limit of approximately 10 requests per minute per IP to `POST /auth/login` and `POST /auth/register`. 3. Return HTTP 429 with a `Retry-After` header when the limit is exceeded. 4. Add a middleware or exception handler that formats the 429 response as JSON (consistent with other API error responses). 5. Write a test that verifies the 429 is returned after the threshold is reached. ## Acceptance criteria - Exceeding the rate limit on `/auth/login` or `/auth/register` returns HTTP 429. - The response body is valid JSON with an error message. - A `Retry-After` header is present. - Requests below the threshold continue to succeed normally.
AI-Manager added the P1agent-readysmallsecurity labels 2026-03-29 08:22:03 +00:00
Author
Owner

This issue has been resolved. SPARC/api.py imports slowapi and applies rate limiting: @limiter.limit("5/minute") on the login endpoint (line 241) and @limiter.limit("10/minute") on the register endpoint (line 274). Closing as completed.

This issue has been resolved. `SPARC/api.py` imports `slowapi` and applies rate limiting: `@limiter.limit("5/minute")` on the login endpoint (line 241) and `@limiter.limit("10/minute")` on the register endpoint (line 274). 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#929