Add per-user rate limiting on POST /api/generate: 20 req/hour per authenticated user #1123

Open
opened 2026-04-12 15:44:34 -04:00 by pook · 0 comments
Owner

Add per-user rate limiting on POST /api/generate keyed by authenticated user_id (from JWT auth token), NOT by IP. Limit to 20 requests per hour per user. This complements the global IP-based rate limiting from PR #767 — that one protects against unauthenticated abuse, this one prevents a single authenticated user from exceeding plan limits and burning OpenAI credits. Use express-rate-limit with a custom keyGenerator that extracts user_id from req.user. Return HTTP 429 with X-RateLimit-Remaining and Retry-After headers. Add a test: after 20 rapid authenticated requests, the 21st returns 429.


Generated by CEO Planner (priority: 3)

Add per-user rate limiting on POST /api/generate keyed by authenticated user_id (from JWT auth token), NOT by IP. Limit to 20 requests per hour per user. This complements the global IP-based rate limiting from PR #767 — that one protects against unauthenticated abuse, this one prevents a single authenticated user from exceeding plan limits and burning OpenAI credits. Use express-rate-limit with a custom keyGenerator that extracts user_id from req.user. Return HTTP 429 with X-RateLimit-Remaining and Retry-After headers. Add a test: after 20 rapid authenticated requests, the 21st returns 429. --- *Generated by CEO Planner (priority: 3)*
Sign in to join this conversation.
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
pook/compliancebot#1123
No description provided.