feat: Redis-backed playground rate limiting with session cookies (#93)#102
Merged
DevanshuNEU merged 4 commits intoDec 13, 2025
Conversation
- Session-based limiting (50/day per device via httpOnly cookie) - IP-based fallback (100/day for shared networks) - Global circuit breaker (10k/hour for cost protection) - Fail-open design if Redis unavailable - PlaygroundLimitResult dataclass for structured responses Part of OpenCodeIntel#93
- Replace in-memory rate limiting with Redis-backed limiter - Add GET /playground/limits endpoint for frontend to check remaining - Add GET /playground/stats for monitoring - Set httpOnly session cookie on first request - Export redis_client from dependencies - Python 3.9 compatible type hints Part of OpenCodeIntel#93
- Fetch limits on mount from GET /playground/limits - Include credentials for session cookie tracking - Use backend response as source of truth for remaining count - Handle 429 rate limit errors with user-friendly message - Remove client-side only tracking (was bypassable on refresh) - Update both LandingPage.tsx and Playground.tsx Part of OpenCodeIntel#93
- Add IS_PRODUCTION flag from ENVIRONMENT env var - Set secure=True for cookie only in production (requires HTTPS) - Development uses secure=False for localhost testing Part of OpenCodeIntel#93
|
@DevanshuNEU is attempting to deploy a commit to the Dev's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes the critical security issue where playground rate limits reset on page refresh, exposing API costs.
Problem
Solution
Implemented a 3-layer Redis-backed rate limiting system:
Architecture
Why These Design Decisions?
New Files
backend/services/playground_limiter.py- Redis-backed rate limiter serviceModified Files
backend/routes/playground.py- Use new limiter, add cookie handlingbackend/dependencies.py- Export redis_clientfrontend/src/pages/LandingPage.tsx- Use backend as source of truthfrontend/src/pages/Playground.tsx- Use backend as source of truthNew API Endpoints
Testing
Security Considerations
httpOnly(can't be accessed by JavaScript)securein production (HTTPS only)samesite=lax(CSRF protection)Closes #93