[kimi] Add rate limiting middleware for Matrix API endpoints (#683) #746

Merged
kimi merged 1 commits from kimi/issue-683 into main 2026-03-21 16:23:17 +00:00

1 Commits

Author SHA1 Message Date
kimi
56720da82f feat: add rate limiting middleware for Matrix API endpoints
Some checks failed
Tests / lint (pull_request) Has been cancelled
Tests / test (pull_request) Has been cancelled
Add RateLimiter class and RateLimitMiddleware for in-memory rate limiting
of /api/matrix/* endpoints with the following features:

- Configurable requests_per_minute per IP (default: 30)
- Returns 429 Too Many Requests when exceeded with Retry-After header
- In-memory storage using deque for efficient timestamp tracking
- Automatic cleanup of stale entries every 60 seconds
- Respects X-Forwarded-For and X-Real-IP headers for proxied requests

Files added/modified:
- src/dashboard/middleware/rate_limit.py (new)
- src/dashboard/middleware/__init__.py (export new classes)
- src/dashboard/app.py (apply middleware to /api/matrix/* routes)
- tests/unit/test_rate_limit.py (comprehensive tests)

Fixes #683
2026-03-21 12:21:26 -04:00