Security News
New Proposed CISA Mandate Would Require Critical Infrastructure to Report Ransom Payments Within 24 Hours
CISA has proposed a set of new rules that would require critical infrastructure to report cyber incidents and ransom payments.
@risingstack/protect
Advanced tools
[![Build Status](https://travis-ci.org/RisingStack/protect.svg?branch=master)](https://travis-ci.org/RisingStack/protect)
Weekly downloads
Readme
Works on Node.js v6 and newer.
The purpose of this module is to provide out-of-box, proactive protection for common security problems, like SQL injection attacks, XSS attacks, brute force, etc...
This module is not a silver bullet, and is not a substitute for security-minded engineering work. But it can help you to achieve your goals.
npm i @risingstack/protect --save
const protect = require('@risingstack/protect')
const express = require('express')
const bodyParser = require('body-parser')
const redis = require('redis')
const client = redis.createClient()
const app = express()
app.use(bodyParser.json({
extended: false
}))
app.use(protect.express.sqlInjection({
body: true,
loggerFunction: console.error
}))
app.use(protect.express.xss({
body: true,
loggerFunction: console.error
}))
app.use(protect.express.rateLimiter({
db: client,
id: (request) => request.connection.remoteAddress
}))
app.get('/', (request, response) => {
response.send('hello protect!')
})
app.post('/login', protect.express.rateLimiter({
db: client,
id: (request) => request.body.email,
// max 10 tries per 2 minutes
max: 10,
duration: 120000
}), (request, response) => {
response.send('wuut logged in')
})
app.listen(3000)
protect.express.sqlInjection([options])
Returns an Express middleware, which checks for SQL injections.
options.body
: if this options is set (true
), the middleware will check for request bodies as well
false
options.loggerFunction
: you can provide a logger function for the middleware to log attacks
noop
protect.express.xss([options])
Returns an Express middleware, which checks for XSS attacks.
options.body
: if this options is set (true
), the middleware will check for request bodies
false
options.loggerFunction
: you can provide a logger function for the middleware to log attacks
noop
protect.express.rateLimiter([options])
Returns an Express middleware, which ratelimits
options.id
: function that returns the id used for ratelimiting - gets the request
as its' first parameter
(request) => request.connection.remoteAddress
options.db
: redis connection instance
options.max
: max requests within options.duration
options.max
: of limit in milliseconds
options.loggerFunction
: you can provide a logger function for the middleware to log attacks
noop
protect.express.headers([options])
The headers object is a reference to the main helmet
object exported.
For docs on the options object, please refer to the helmet documentation.
As mentioned, this module isn't a silver bullet to solve your security issues completely. The following information is provided to hopefully point you in the right direction for solving other security concerns or alternatives that may be useful based on your budget or scale.
There are plenty of other areas that you should be concerned about when it comes to security, that this module doesn't cover (yet or won't) for various reasons. Here are a few that are worth researching:
If you have the resources available (budget or hosting environment), a dedicated WAF (Web Application Firewall) can offer a robust solution to various security issues, such as blocking potential attackers and flagging their activity.
FAQs
[![Build Status](https://travis-ci.org/RisingStack/protect.svg?branch=master)](https://travis-ci.org/RisingStack/protect)
The npm package @risingstack/protect receives a total of 161 weekly downloads. As such, @risingstack/protect popularity was classified as not popular.
We found that @risingstack/protect demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 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
CISA has proposed a set of new rules that would require critical infrastructure to report cyber incidents and ransom payments.
Security News
Redis is no longer OSS, breaking its explicit commitment to remain under the BSD 3-Clause License forever. This has angered contributors who are now working to fork the software.
Product
Socket AI now enables 'AI detected potential malware' alerts by default, ensuring users benefit from AI-powered state-of-the-art malware detection without needing to opt-in.