feat(security) ✨ implement API rate limiting with throttler #21#21
Merged
Mattic77 merged 1 commit intoMay 22, 2026
Merged
Conversation
- install and configure @nestjs/throttler globally - set default global limit to 100 requests per minute - apply strict limits to sensitive auth endpoints (login, signup, OTP) - implement spam protection for friend requests
Contributor
There was a problem hiding this comment.
Pull request overview
Implements API rate limiting across the NestJS backend using @nestjs/throttler, applying a global request cap and stricter per-route throttles for sensitive/spam-prone endpoints.
Changes:
- Added global throttling configuration (100 requests per minute) and registered
ThrottlerGuardas a globalAPP_GUARD. - Applied stricter
@Throttle(...)limits tosignup,signup-otp, andsigninauth routes. - Added a per-route throttle for
POST /friends/request/:idto reduce request spam/harassment.
Reviewed changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/app.module.ts | Adds ThrottlerModule global configuration and registers ThrottlerGuard as a global guard. |
| src/auth/auth.controller.ts | Adds route-level throttling for signup, OTP, and signin endpoints. |
| src/friend/friend.controller.ts | Adds route-level throttling for friend request creation endpoint. |
| package.json | Adds @nestjs/throttler dependency. |
| package-lock.json | Locks @nestjs/throttler dependency resolution/details. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
GitHub Issue
Closes GH-21
Description 📝
This PR implements API Rate Limiting across the entire backend using the
@nestjs/throttlerpackage. It provides a global safety layer and strict protection for sensitive endpoints to prevent brute-force attacks and spam.Type of Change
Changes
AppModule.POST /auth/signin: 10 attempts per minute.POST /auth/signup: 5 attempts per minute.POST /auth/signup-otp: 3 attempts per minute (Protects email/OTP costs).POST /friends/request/:idto 10 per minute to prevent harassment.ThrottlerGuardas a global APP_GUARD.Headers 📡
The API will now return the following standard rate-limit headers:
X-RateLimit-Limit: Maximum requests allowed in the window.X-RateLimit-Remaining: Remaining requests in the current window.X-RateLimit-Reset: Time (in seconds) until the window resets.Screenshots 📷 (if applicable)
(No UI changes)