
Security News
Axios Maintainer Confirms Social Engineering Attack Behind npm Compromise
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.
@api-guard/trafix
Advanced tools
A NestJS guard for API rate limiting using Redis and sliding window algorithm
API Rate Limiter is a powerful guard for NestJS that restricts the number of requests a client can make within a specific time window. It utilizes Redis as an in-memory store for efficient and scalable request tracking.
npm install @api-guard/trafix
Configure the TrafixModule in your app.module.ts:
import { Module } from '@nestjs/common';
import { TrafixModule } from '@api-guard/trafix';
import { ConfigModule, ConfigService } from '@nestjs/config';
@Module({
imports: [
ConfigModule.forRoot(),
TrafixModule.forRootAsync({
redis: {
imports: [ConfigModule],
inject: [ConfigService],
useFactory: (configService: ConfigService) => ({
type: 'single',
url: configService.get<string>('REDIS_URL'),
options: {
password: configService.get<string>('REDIS_PASSWORD'),
},
}),
},
config: {
maxRequests: 10,
windowMs: 60000, // 60 seconds
message: 'Too many requests, please try again later.',
statusCode: 429,
ipHeader: 'x-real-ip', // Header to extract IP address
responseHeaders: ['X-RateLimit-Limit', 'X-RateLimit-Remaining'],
},
}),
],
})
export class AppModule {}
redis: Redis connection configuration
url: Redis server URLoptions.password: Redis server password (if required)config: Rate limiting configuration
maxRequests: Maximum number of requests allowed in the time windowwindowMs: Time window in millisecondsmessage: Custom error message for rate limit exceeded (optional)statusCode: HTTP status code for rate limit exceeded (optional)ipHeader: Custom header to extract client IP address (optional)responseHeaders: Custom headers to include in the response (optional)Use the TrafixGuard in your controllers:
import { Controller, Get, UseGuards } from '@nestjs/common';
import { TrafixGuard } from '@api-guard/trafix';
@Controller('app')
export class AppController {
@UseGuards(TrafixGuard)
@Get('')
getData() {
// Your controller logic here
}
}
We welcome contributions to improve API Rate Limiter! To contribute:
git checkout -b feature/AmazingFeature)git commit -m 'Add some AmazingFeature')git push origin feature/AmazingFeature)Please ensure your code follows NestJS best practices and includes relevant tests.
This project is licensed under the MIT License - see the LICENSE file for details.
For more information and detailed documentation, please refer to our official documentation.
FAQs
A NestJS guard for API rate limiting using Redis and sliding window algorithm
The npm package @api-guard/trafix receives a total of 2 weekly downloads. As such, @api-guard/trafix popularity was classified as not popular.
We found that @api-guard/trafix demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.

Security News
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.