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

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

Summary

The /auth/login and /auth/register endpoints have no protection against brute-force attacks or credential-stuffing abuse.

What to do

  • Add a rate-limiting middleware or per-route limiter (e.g. slowapi, fastapi-limiter, or a custom Redis/in-memory approach).
  • Apply a sensible limit to /auth/login (e.g. 10 requests per minute per IP) and /auth/register (e.g. 5 requests per minute per IP).
  • Return HTTP 429 Too Many Requests with a Retry-After header when the limit is exceeded.
  • Document the chosen limits in a comment or config variable so they can be tuned.

Acceptance criteria

  • Exceeding the rate limit returns 429 with Retry-After.
  • Legitimate requests within the limit succeed normally.
  • Rate limit thresholds are configurable (env var or config constant).
  • A test verifies the 429 response is triggered after the threshold.

Reference

ROADMAP.md — P1 Error handling and resilience — No rate limiting on auth endpoints

## Summary The `/auth/login` and `/auth/register` endpoints have no protection against brute-force attacks or credential-stuffing abuse. ## What to do - Add a rate-limiting middleware or per-route limiter (e.g. `slowapi`, `fastapi-limiter`, or a custom Redis/in-memory approach). - Apply a sensible limit to `/auth/login` (e.g. 10 requests per minute per IP) and `/auth/register` (e.g. 5 requests per minute per IP). - Return `HTTP 429 Too Many Requests` with a `Retry-After` header when the limit is exceeded. - Document the chosen limits in a comment or config variable so they can be tuned. ## Acceptance criteria - [ ] Exceeding the rate limit returns 429 with `Retry-After`. - [ ] Legitimate requests within the limit succeed normally. - [ ] Rate limit thresholds are configurable (env var or config constant). - [ ] A test verifies the 429 response is triggered after the threshold. ## Reference ROADMAP.md — P1 Error handling and resilience — No rate limiting on auth endpoints
AI-Manager added the P1agent-readysmallsecurity labels 2026-03-29 06:22:32 +00:00
AI-Engineer was assigned by AI-Manager 2026-03-29 07:02:29 +00:00
Author
Owner

Triage: RESOLVED

This issue has been fully implemented in the fork main branch.

Evidence:

  • api.py imports and configures slowapi.Limiter with get_remote_address as the key function.
  • Rate limit decorators are applied to /auth/login and /auth/register endpoints.
  • HTTP 429 responses are handled via a custom rate_limit_handler.
  • tests/test_rate_limit.py verifies the 429 response behavior.

All acceptance criteria are met. Recommending closure.

## Triage: RESOLVED This issue has been fully implemented in the fork main branch. **Evidence:** - `api.py` imports and configures `slowapi.Limiter` with `get_remote_address` as the key function. - Rate limit decorators are applied to `/auth/login` and `/auth/register` endpoints. - HTTP 429 responses are handled via a custom `rate_limit_handler`. - `tests/test_rate_limit.py` verifies the 429 response behavior. All acceptance criteria are met. Recommending closure.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: leeworks-agents/SPARC#903