Skip to content

[Phase 2] Implement API Rate Limiting for Security #167

Description

@frankbria

Summary

Add rate limiting to API endpoints to prevent abuse and protect against denial-of-service attacks.

Context

Currently, the API endpoints have no rate limiting mechanism. This exposes the application to:

  • Brute force attacks on authentication endpoints
  • Resource exhaustion through excessive API calls
  • Potential cost overruns from unbounded AI API usage

Requirements

  • Implement per-user rate limiting for authenticated endpoints
  • Implement per-IP rate limiting for unauthenticated endpoints (login, register)
  • Configure appropriate limits per endpoint category:
    • Authentication: 5-10 requests/minute
    • Standard API: 60-100 requests/minute
    • AI/expensive operations: 10-20 requests/minute
  • Return proper 429 Too Many Requests responses with Retry-After header
  • Add rate limit headers to responses (X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset)

Technical Considerations

  • Use FastAPI's built-in support or libraries like slowapi
  • Consider Redis for distributed rate limiting in production
  • In-memory rate limiting acceptable for single-instance deployments

Priority

P2 - Medium priority for beta. Important for security but not blocking MVP functionality.

Metadata

Metadata

Assignees

No one assigned

    Labels

    phase-2Phase 2: Server Layer as Thin Adaptersecurity

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions