Skip to content

feat(auth): add support for internal service-to-service request handling in throttler#1860

Merged
Artuomka merged 1 commit into
mainfrom
backend_improvements
Jul 22, 2026
Merged

feat(auth): add support for internal service-to-service request handling in throttler#1860
Artuomka merged 1 commit into
mainfrom
backend_improvements

Conversation

@Artuomka

@Artuomka Artuomka commented Jul 22, 2026

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • Performance
    • Internal service-to-service requests are no longer subject to global rate limiting, improving communication reliability between backend services.
  • Security
    • Requests authenticated through internal service credentials are identified and handled appropriately while external traffic remains protected by throttling.

Copilot AI review requested due to automatic review settings July 22, 2026 13:36
@Artuomka
Artuomka enabled auto-merge July 22, 2026 13:36
@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: c0f6d8ab-2807-4156-8979-f76ed05292c1

📥 Commits

Reviewing files that changed from the base of the PR and between c24e6e7 and 7b08392.

📒 Files selected for processing (3)
  • backend/src/app.module.ts
  • backend/src/authorization/cognito-decoded.interface.ts
  • backend/src/authorization/saas-auth.middleware.ts

📝 Walkthrough

Walkthrough

The request interface and authentication middleware now mark authenticated microservice calls, while the global throttler skips requests carrying that marker.

Changes

Microservice throttling exemption

Layer / File(s) Summary
Internal request flag and middleware marking
backend/src/authorization/cognito-decoded.interface.ts, backend/src/authorization/saas-auth.middleware.ts
Adds the optional isMicroserviceRequest request property and sets it during microservice-JWT authentication.
Global throttler exemption
backend/src/app.module.ts
Adds a typed skipIf callback that bypasses throttling for marked microservice requests.

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
Loading

Suggested reviewers: copilot

Poem

A rabbit hops through service lanes,
With flags instead of throttling chains.
The middleware marks the way,
The limiter skips without delay.
Internal calls go on their run—
A carrot cheers: the flow is done! 🐇

🚥 Pre-merge checks | ✅ 6
✅ Passed checks (6 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: exempting internal service-to-service requests from throttling.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Security Check ✅ Passed PASS: the throttle bypass is only set after successful microservice JWT verification, and no user-controlled path writes the flag.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch backend_improvements

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 SaaSAuthMiddleware via req.isMicroserviceRequest.
  • Extends the request typing (IRequestWithCognitoInfo) to include the new flag with documentation.
  • Configures the global Nest throttler to skipIf the 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.

Comment thread backend/src/app.module.ts
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';
Comment thread backend/src/app.module.ts
Comment on lines +69 to +76
// 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;
},
@Artuomka
Artuomka merged commit 42c8174 into main Jul 22, 2026
17 of 18 checks passed
@Artuomka
Artuomka deleted the backend_improvements branch July 22, 2026 13:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants