express-shield-securekit
v1.0.20
Published
A modular security middleware toolkit for Express.js with built-in rate limiting, SQL injection protection, and XSS sanitization.
Maintainers
Readme
Express Shield SecureKit
A modular security middleware toolkit for Express.js with built-in protection against common web attacks including SQL Injection, XSS, and request flooding.
✨ Features
- ⚡ Rate Limiting (in-memory & Redis)
- 🛡️ SQL Injection Detection & Blocking
- 🚫 XSS Protection using sanitization
- 🔌 Modular Middleware Architecture
📦 Installation
npm install express-shield-securekitUsage
Method 1: Manual Middleware Setup (Flexible but Verbose)
import { expressRateLimiter, sanitizeMiddleware } from "express-shield-securekit";
const app = express();
app.use(express.json());
// Rate Limiter Middleware
app.use(expressRateLimiter({
windowMs: 60 * 1000, // 1 minute window
max: 5,
message: "Too many requests. Please try again later."
}));
// Global Sanitizer Middleware (XSS + SQL Injection)
app.use(sanitizeMiddleware);
app.post("/test", (req, res) => {
res.json({
success: true,
message: "Request passed all security checks!",
sanitizedBody: req.body,
});
});
app.listen(3000, () => {
console.log("Server running on http://localhost:3000");
});Method 2: Easy Integration (Recommended)
const { secureMiddleware } = require("express-shield-securekit");
const app = express();
app.use(express.json());
rateLimitOptions = {
windowMs: 60 * 1000,
max: 5,
message: "Too many requests. Please try again later."
}
app.use(secureMiddleware({
rateLimit: rateLimitOptions,
sanitizeMiddleware: true
}))
app.post("/test", (req, res) => {
res.json({
success: true,
message: "Request passed all security checks!",
sanitizedBody: req.body,
});
});
app.listen(3000, () => {
console.log("Server running on http://localhost:3000");
});🧱 Middleware Provided
expressRateLimiter(options)
Simple rate limiter middleware for Express.
Options:
windowMs— Duration of time window in millisecondsmax— Maximum requests allowed per IP in the time windowmessage— Custom error message on rate limit exceeded
Example:
app.use(expressRateLimiter({
windowMs: 60 * 1000, // 1 minute
max: 10,
message: "Too many requests. Try again in a minute."
}));sanitizeMiddleware
- Clean all incoming
req.body,req.queryandreq.params. - Detect
XSS scripts using xss packageandSQL injection patterns. - Automatically blocks the request with 400 Bad Request if threats are found. If malicious input is detected.
Future Plans (v2+)
- Secure HTTP Headers - Add support similar to Helmet
- CSRF Token Middleware – Protection against cross-site request forgery
- AI-based anomaly detection for malicious payloads - Block suspicious payloads with pattern learning
- Rate Limiting for Microservices - Redis/pub-sub friendly distributed throttling
Test
npm testAuthor
Made with ❤️ by Syed Bakhtawar Fahim
