feat(auth): add support for internal service-to-service request handling in throttler#1860
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughThe request interface and authentication middleware now mark authenticated microservice calls, while the global throttler skips requests carrying that marker. ChangesMicroservice throttling exemption
Estimated code review effort: 2 (Simple) | ~10 minutes Sequence Diagram(s)sequenceDiagram
participant Client
participant SaaSAuthMiddleware
participant ThrottlerModule
Client->>SaaSAuthMiddleware: Send authenticated microservice request
SaaSAuthMiddleware->>SaaSAuthMiddleware: Set isMicroserviceRequest = true
SaaSAuthMiddleware->>ThrottlerModule: Pass request
ThrottlerModule->>ThrottlerModule: Skip rate limiting
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 6✅ Passed checks (6 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Pull request overview
Adds a mechanism to identify internal service-to-service HTTP requests (authenticated via the microservice JWT) and exempts them from global rate limiting to avoid unintended collective throttling when traffic originates from shared satellite IPs.
Changes:
- Flags microservice-JWT-authenticated requests in
SaaSAuthMiddlewareviareq.isMicroserviceRequest. - Extends the request typing (
IRequestWithCognitoInfo) to include the new flag with documentation. - Configures the global Nest throttler to
skipIfthe request is marked as an internal microservice call.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| backend/src/authorization/saas-auth.middleware.ts | Marks microservice-authenticated requests as internal so throttling logic can treat them differently. |
| backend/src/authorization/cognito-decoded.interface.ts | Extends the request interface with isMicroserviceRequest and documents its purpose. |
| backend/src/app.module.ts | Adds a global throttler skipIf based on the new request flag. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| import { ThrottlerGuard, ThrottlerModule } from '@nestjs/throttler'; | ||
| import { AICoreModule } from './ai-core/ai-core.module.js'; | ||
| import { AppController } from './app.controller.js'; | ||
| import { IRequestWithCognitoInfo } from './authorization/cognito-decoded.interface.js'; |
| // Skip rate limiting for internal service-to-service calls: they are | ||
| // gated by SaaSAuthMiddleware (microservice JWT), which flags the request. | ||
| // All such calls share the satellites' IPs, so a per-IP limit would | ||
| // throttle them collectively; auth already bounds who can make them. | ||
| skipIf: (context) => { | ||
| const req = context.switchToHttp().getRequest<IRequestWithCognitoInfo>(); | ||
| return req.isMicroserviceRequest === true; | ||
| }, |
Summary by CodeRabbit