Problem
Currently, there is no rate limiting on the web application. A single user could:
- Spam ChatKit messages and rack up AI billing costs
- Overwhelm the API with excessive requests
- Impact other users' experience
The /workspace page with ChatKit integration is the highest risk area.
Context
- Deployment: Kubernetes cluster
- Dapr: Sidecar available (can be attached to web project)
- Current state: Zero rate limiting infrastructure
Scope of Work
Files to Modify/Create
| File |
Change |
Purpose |
apps/web/src/lib/rate-limit.ts |
NEW |
Dapr state-backed rate limiter |
apps/web/src/app/api/chatkit/route.ts |
Add rate check |
Protect AI billing |
apps/web/src/app/api/proxy/[...path]/route.ts |
Add rate check |
General API protection |
components/ratelimit-statestore.yaml |
NEW (if needed) |
Dapr state component |
| K8s deployment annotations |
Update |
Attach Dapr sidecar |
Rate Limits (Proposed)
| Endpoint |
Limit |
Window |
Rationale |
/api/chatkit |
20 messages |
1 minute |
AI billing protection |
/api/proxy/* |
200 requests |
1 minute |
General abuse prevention |
Implementation Options
Option A: Dapr Built-in Rate Limit Middleware (Simplest)
- Pros: Config-only, no code changes
- Cons: Global rate limit, not per-user
Option B: Dapr State Store + Code (Recommended)
- Pros: Per-user limits, distributed across pods, window-based
- Cons: Requires state store component
Option C: Redis Sidecar
- Pros: Battle-tested, feature-rich
- Cons: Additional dependency to manage
Questions to Answer Before Implementation
Technical Details
User Identification
- JWT
sub claim available from taskflow_id_token cookie
- Already extracted in proxy route (line 58-60)
Integration Points
apps/web/src/app/api/proxy/[...path]/route.ts:58-60 - JWT extraction
apps/web/src/app/api/chatkit/route.ts - ChatKit proxy
apps/api/src/taskflow_api/main.py:85-92 - Backend middleware (optional)
Response on Rate Limit
{
"error": "Rate limit exceeded. Try again in 45s"
}
HTTP Status: 429 Too Many Requests
Header: Retry-After: 45
Estimation
| Scenario |
Effort |
| Dapr already configured |
2-3 hours |
| Need to set up Dapr state |
4-5 hours |
| Full Redis setup |
6-8 hours |
Acceptance Criteria
Labels
enhancement security billing apps/web
Problem
Currently, there is no rate limiting on the web application. A single user could:
The
/workspacepage with ChatKit integration is the highest risk area.Context
Scope of Work
Files to Modify/Create
apps/web/src/lib/rate-limit.tsapps/web/src/app/api/chatkit/route.tsapps/web/src/app/api/proxy/[...path]/route.tscomponents/ratelimit-statestore.yamlRate Limits (Proposed)
/api/chatkit/api/proxy/*Implementation Options
Option A: Dapr Built-in Rate Limit Middleware (Simplest)
Option B: Dapr State Store + Code (Recommended)
Option C: Redis Sidecar
Questions to Answer Before Implementation
X-RateLimit-Remaining,Retry-After)?Technical Details
User Identification
subclaim available fromtaskflow_id_tokencookieIntegration Points
apps/web/src/app/api/proxy/[...path]/route.ts:58-60- JWT extractionapps/web/src/app/api/chatkit/route.ts- ChatKit proxyapps/api/src/taskflow_api/main.py:85-92- Backend middleware (optional)Response on Rate Limit
{ "error": "Rate limit exceeded. Try again in 45s" }HTTP Status:
429 Too Many RequestsHeader:
Retry-After: 45Estimation
Acceptance Criteria
Labels
enhancementsecuritybillingapps/web