feat(security): add payer-aware rate limiting (#670) - #723
Conversation
|
@nupedev 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! 🚀 |
SummaryCloses #670 Adds dual-mode rate limiting for anonymous traffic and authenticated payment or meter-management requests. ChangesAnonymous Each payer receives a sliding one-hour bucket with a default maximum of 50 requests. The limiter uses Redis via The Verification
|
Summary
Closes #670
Adds dual-mode rate limiting for anonymous traffic and authenticated payment or meter-management requests.
Changes
Anonymous
/apitraffic keeps an IP-based limiter with defaults of 100 requests per 15 minutes. Payment and meter-management routes now run a payer-aware limiter afterexpress.json()andexpress.urlencoded()so the validatedpayer,owner,new_owner, or explicitX-Payer-Addressidentity is available.Each payer receives a sliding one-hour bucket with a default maximum of 50 requests. The limiter uses Redis via
iorediswhenREDIS_URLis configured and falls back to a per-process in-memory Map when Redis is unavailable or not configured. Redis operations use an atomic sorted-set script, and a store failure fails over to memory rather than taking the API offline. StandardRateLimit-*,X-RateLimit-*, andRetry-Afterheaders are returned for payer-scoped responses.Verification
npm test -- --run tests/rate-limit.integration.test.ts— 3 passed.git diff --check— passed.The backend’s full TypeScript build still encounters unrelated pre-existing parser errors in
src/index.tsandsrc/iot/bridge.ts; no diagnostics were produced by the focused rate-limit test.