feat: implement token bucket rate limiting with burst handling and ti…#294
Conversation
…er awareness - Add TokenBucketRateLimit middleware (backend/src/middleware/rate-limit.ts) - Configurable capacity, refill rate, and burst allowance per tier - In-memory store with Redis fallback via atomic Lua script - Fails open on Redis errors to avoid availability impact - Per-endpoint configs for /invoice, /verification, /stellar - User tier differentiation: free / pro / enterprise - X-RateLimit-* headers + Retry-After on 429 responses - Ring-buffer analytics with getAnalyticsSummary() - Add GET /api/v1/rate-limit/analytics endpoint - Replace fixed-window tieredRateLimit in index.ts with token bucket - Update .env.example with Redis and burst config vars
|
@shaaibu7 is attempting to deploy a commit to the smartdevs17's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
@distributed-nerd Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
|
This PR has merge conflicts that must be resolved before it can be merged. To fix:
Once resolved, the PR will be automatically merged on the next run. 🤖 Drips Wave Review Agent |
2 similar comments
|
This PR has merge conflicts that must be resolved before it can be merged. To fix:
Once resolved, the PR will be automatically merged on the next run. 🤖 Drips Wave Review Agent |
|
This PR has merge conflicts that must be resolved before it can be merged. To fix:
Once resolved, the PR will be automatically merged on the next run. 🤖 Drips Wave Review Agent |
|
| GitGuardian id | GitGuardian status | Secret | Commit | Filename | |
|---|---|---|---|---|---|
| 32145778 | Triggered | Generic Password | aaed709 | backend/src/relayer/tests/signature.test.ts | View secret |
🛠 Guidelines to remediate hardcoded secrets
- Understand the implications of revoking this secret by investigating where it is used in your code.
- Replace and store your secret safely. Learn here the best practices.
- Revoke and rotate this secret.
- If possible, rewrite git history. Rewriting git history is not a trivial act. You might completely break other contributing developers' workflow and you risk accidentally deleting legitimate data.
To avoid such incidents in the future consider
- following these best practices for managing and storing secrets including API keys and other credentials
- install secret detection on pre-commit to catch secret before it leaves your machine and ease remediation.
🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.
|
@Smartdevs17 conflicts resolved |
feat: Token bucket rate limiting with burst handling and tier awareness
Replaces the fixed-window
tieredRateLimitwith a proper token bucket algorithm that supports burst handling, per-endpoint limits, user tier differentiation, and distributed state via Redis.Changes
backend/src/middleware/rate-limit.ts(new)capacity,refillRate, andburstAllowanceper tierrefillRate/sup tocapacity + burstAllowanceX-RateLimit-Limit,X-RateLimit-Remaining,X-RateLimit-Reset,X-RateLimit-Policy,X-RateLimit-Tierheaders on every response429withRetry-Afterheader and structured error body when bucket is emptyrecordAnalyticsEvent,getAnalyticsSummary)backend/src/routes/rate-limit-analytics.ts(new)GET /api/v1/rate-limit/analytics?windowMs=60000backend/src/index.tstieredRateLimitandexpress-rate-limitinvoice limitertokenBucketRateLimitas the global/api/middlewareendpointConfigoverride/api/v1/rate-limitbackend/.env.exampleREDIS_URLand per-tier burst/refill configDefault tier limits
Per-endpoint overrides
/api/v1/invoice/api/v1/verification/api/v1/stellarEdge cases handled
closes #224