
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
shield-guard
Advanced tools
Advanced rate limiting middleware for Node.js applications with enterprise-grade features and flexible configuration options
Advanced rate limiting middleware for Node.js applications with enterprise-grade features and flexible configuration options.
npm install shield-guard
import express from 'express';
import { ShieldGuard } from 'shield-guard';
const app = express();
const shield = new ShieldGuard({
windowMs: 15 * 60 * 1000, // 15 minutes
limit: 100, // Limit each IP to 100 requests per window
banTime: 30 * 60 * 1000, // Ban for 30 minutes after limit exceeded
message: {
error: true,
status: 429,
message: 'Too many requests',
details: {
limit: 100,
windowInMinutes: 15
}
}
});
app.use(shield.middleware());
const shield = new ShieldGuard({
windowMs: 15 * 60 * 1000,
limit: 100,
banTime: 60 * 60 * 1000, // 1 hour ban
onBan: async (req, res) => {
await logBannedIP(req.ip);
res.status(403).json({
error: 'IP banned',
banExpiration: new Date(Date.now() + 60 * 60 * 1000)
});
}
});
const shield = new ShieldGuard({
windowMs: 60 * 1000, // 1 minute
limit: (req) => {
switch (req.path) {
case '/api/auth':
return 5; // 5 login attempts per minute
case '/api/search':
return 30; // 30 searches per minute
default:
return 100; // Default limit
}
}
});
const shield = new ShieldGuard({
proxyValidation: true,
blockByUserAgent: true,
allowedUserAgents: ['Mozilla', 'Chrome', 'Safari', 'Edge'],
headers: {
remaining: 'X-RateLimit-Remaining',
reset: 'X-RateLimit-Reset',
total: 'X-RateLimit-Limit',
retryAfter: 'Retry-After',
banExpire: 'X-Ban-Expires'
}
});
const shield = new ShieldGuard({
store: new RedisStore({
client: redis.createCluster({
nodes: [
{ host: 'localhost', port: 6379 },
{ host: 'localhost', port: 6380 }
]
}),
prefix: 'shield:',
syncInterval: 1000
}),
distributed: true
});
const shield = new ShieldGuard({
enableLogging: true,
logLevel: 'info',
logHandler: (log) => {
console.log(`[${log.type}] IP: ${log.ip}`);
console.log(`Path: ${log.path}`);
console.log(`Rate: ${log.hits}/${log.limit}`);
console.log(`User Agent: ${log.userAgent}`);
if (log.banExpiration) {
console.log(`Ban Expires: ${new Date(log.banExpiration)}`);
}
}
});
const shield = new ShieldGuard({
message: async (req) => {
const timeLeft = await getRemainingTime(req.ip);
return {
error: true,
code: 'RATE_LIMIT_EXCEEDED',
message: 'Rate limit exceeded',
details: {
timeLeft: timeLeft,
nextTry: new Date(Date.now() + timeLeft),
path: req.path,
method: req.method
}
};
}
});
Shield Guard provides detailed metrics for monitoring:
const shield = new ShieldGuard({
metrics: {
enable: true,
prometheus: true,
prefix: 'shield_guard_',
labels: ['path', 'method', 'status']
}
});
| Option | Type | Description | Default |
|---|---|---|---|
windowMs | number | Time window for rate limiting | 60000 |
limit | number | function | Request limit per window | 100 |
banTime | number | Ban duration in ms | 1800000 |
statusCode | number | HTTP status code | 429 |
message | string | object | function | Response message | 'Too many requests' |
headers | object | Custom headers | {} |
store | Store | Storage backend | MemoryStore |
distributed | boolean | Enable distribution | false |
burstLimit | number | Burst limit | 0 |
burstTime | number | Burst window | 1000 |
blockByCountry | boolean | Geo-blocking | false |
proxyValidation | boolean | Validate proxies | false |
enableLogging | boolean | Enable logging | false |
Configure Ban System
const shield = new ShieldGuard({
banTime: 30 * 60 * 1000,
onBan: async (req) => {
await notifyAdmin(req.ip);
}
});
Use Custom Storage for Production
const shield = new ShieldGuard({
store: new RedisStore(),
distributed: true,
syncInterval: 1000
});
Implement Path-Specific Limits
const shield = new ShieldGuard({
limit: (req) => {
return req.path.startsWith('/api') ? 50 : 100;
}
});
Enable Comprehensive Logging
const shield = new ShieldGuard({
enableLogging: true,
logLevel: 'info',
logHandler: customLogHandler
});
MIT © Shield Guard Contributors
FAQs
Advanced rate limiting middleware for Node.js applications with enterprise-grade features and flexible configuration options
The npm package shield-guard receives a total of 1 weekly downloads. As such, shield-guard popularity was classified as not popular.
We found that shield-guard demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 0 open source maintainers 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
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

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.