feat: Redis-backed sliding window throttling with @Throttle decorator#882
Merged
Merged
Conversation
- Add src/common/throttler/ module: - throttle.decorator.ts: @Throttle(limit, ttl) and @SkipThrottle() - throttler.service.ts: sliding window via Redis ZADD/ZCARD/ZREMRANGEBYSCORE - throttler.guard.ts: IP-based (unauthenticated) + userId-based (authenticated) tracking, trusted IP whitelist (THROTTLE_TRUSTED_IPS env), Retry-After header - throttler.module.ts: exports ThrottlerService + ThrottlerGuard - Register ThrottlerGuard globally via APP_GUARD in AppModule - Auth endpoints: @Throttle(5,60) nonce, @Throttle(10,60) login, @Throttle(20,60) refresh - Global defaults: 100 req/min authenticated, 20 req/min unauthenticated - Remove old inline enforceRateLimit from AuthController - Also includes normalizeWalletAddress utility (wallet.utils.ts) and pre-existing merge conflict fixes from feat/normalize-wallet-address Tests: 12/12 throttler, 3/3 auth controller (15 total)
|
@Shecodes174 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 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.
closes #696
Summary
Implements Redis-backed rate limiting with a custom
@Throttle()decorator andThrottlerGuardthat uses a sliding window algorithm.New files:
src/common/throttler/throttle.decorator.ts@Throttle(limit, ttl)and@SkipThrottle()decoratorsthrottler.service.tsZADD/ZCARD/ZREMRANGEBYSCOREthrottler.guard.tsCanActivateguard — IP tracking (unauth) / userId tracking (auth)throttler.module.tsthrottler.spec.tsAcceptance criteria
@Throttle(10, 60)= 10 req/60sTHROTTLE_TRUSTED_IPSenv var (comma-separated)Auth endpoint limits
GET /auth/nonce/:walletAddress→@Throttle(5, 60)POST /auth/login→@Throttle(10, 60)POST /auth/refresh→@Throttle(20, 60)Configuration
Tests
15/15 pass (12 throttler + 3 auth controller)