-
-
Notifications
You must be signed in to change notification settings - Fork 162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(api): implement rate limiting in the api #793
base: develop
Are you sure you want to change the base?
feat(api): implement rate limiting in the api #793
Conversation
Changes Made: Added a RateLimitGuard that extends ThrottlerGuard to enforce API rate limits. Configured ThrottlerModule with a 60-second window allowing 10 requests per IP. Fixed type issues (remainingPoints and retryAfter do not exist in ThrottlerLimitDetail). Ensured the guard correctly handles excessive requests by throwing 429 Too Many Requests. Testing & Verification: Successfully blocked more than 10 requests within 60 seconds. Requests resumed normally after the time window expired.
…uth before limiting.
…th before limiting.
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
keyshade.json | ||
pnpm-lock.yaml |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this shouldnt go in gitignore
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you revert the changes in this entire file?
|
||
throw new HttpException( | ||
{ | ||
message: 'Too many requests. Please try again later.' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Return a constructErrorBody
|
||
// Logging for debugging purposes | ||
this.logger.debug(`Rate limiting applied to key: ${key}`) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think you have done the implementation of cache to actually make the logic work
@Dhanushranga1, please resolve all open reviews! |
@Dhanushranga1, please resolve all open reviews; otherwise this PR will be closed after Sun Mar 02 2025 13:10:59 GMT+0000 (Coordinated Universal Time)! |
Hey rajdip, sorry man, got caught up with some work, will start as soon as i can |
User description
Description
Implements rate limiting functionality to protect API endpoints from abuse. This change:
Fixes #12
Dependencies
Future Improvements
Endpoint-Specific Rate Limiting
@MaxRequestsPerUser(limit: number)
decoratorCache-Based Rate Limit Storage
(userId, endpoint, lockedUntil)
Team name for fossHack20225: BunLock
Team Members:
@anaypurohit0907
@Dhanushranga1
@hanish-rishen
Thanks @rajdip-b for guiding us and answering all of our questions.
Screenshots
Developer's checklist
Documentation Update
PR Type
Enhancement
Description
Implemented rate limiting for API requests using
ThrottlerModule
.Added
RateLimitGuard
to enforce rate limits per user or IP.Configured guard execution order: Auth → API Key → Rate Limit.
Improved OTP validation and cleanup logic in
AuthService
.Changes walkthrough 📝
auth.service.ts
Refactored OTP validation and cleanup logic
apps/api/src/auth/service/auth.service.ts
app.module.ts
Integrated rate limiting module and guard
apps/api/src/app/app.module.ts
ThrottlerModule
for rate limiting configuration.RateLimitGuard
to enforce rate limits.rate-limit-guard.ts
Added custom RateLimitGuard for API requests
apps/api/src/common/rate-limit-guard.ts
RateLimitGuard
extendingThrottlerGuard
.