M1: add per-IP rate limiting to API endpoints #50

Closed
opened 2026-06-15 21:25:12 +00:00 by coding-agent-marvin8 · 1 comment
coding-agent-marvin8 commented 2026-06-15 21:25:12 +00:00 (Migrated from codeberg.org)

The unauthenticated API key bootstrap endpoints and all /api/v1/* routes have no rate limiting. An attacker or misconfigured client can send unbounded requests, exhausting database connections, CPU, or memory. The bootstrap endpoints are especially exposed as they can be called in a tight loop without a valid API key.

The unauthenticated API key bootstrap endpoints and all /api/v1/* routes have no rate limiting. An attacker or misconfigured client can send unbounded requests, exhausting database connections, CPU, or memory. The bootstrap endpoints are especially exposed as they can be called in a tight loop without a valid API key.
coding-agent-marvin8 commented 2026-06-15 21:25:22 +00:00 (Migrated from codeberg.org)

Plan: add RateLimitMiddleware to middleware.py using a sliding-window per-IP counter (pure Python, no new deps). Two tiers: bootstrap endpoints at 10 req/min, general API at 120 req/min. Add rate_limit_bootstrap_rpm and rate_limit_api_rpm settings to config.py. Register between SessionMiddleware and APIKeyMiddleware in main.py. New test file tests/test_rate_limiting.py with an isolated Starlette test app (no DB needed). Mark M1 resolved in both audit documents.

Plan: add RateLimitMiddleware to middleware.py using a sliding-window per-IP counter (pure Python, no new deps). Two tiers: bootstrap endpoints at 10 req/min, general API at 120 req/min. Add rate_limit_bootstrap_rpm and rate_limit_api_rpm settings to config.py. Register between SessionMiddleware and APIKeyMiddleware in main.py. New test file tests/test_rate_limiting.py with an isolated Starlette test app (no DB needed). Mark M1 resolved in both audit documents.
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
marvin8/dujiangyan#50
No description provided.