Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
koa-protect
Advanced tools
Readme
Works on Node.js v7 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 koa-protect --save
const protect = require('koa-protect')
const Koa = require('koa')
const bodyParser = require('koa-bodyparser')
const redis = require('redis')
const client = redis.createClient()
const app = new Koa()
app.use(bodyParser.json())
const router = require('koa-router')()
app.use(protect.koa.sqlInjection({
body: true,
loggerFunction: console.error
}))
app.use(protect.koa.xss({
body: true,
loggerFunction: console.error
}))
app.use(ratelimit({
db: client,
duration: 60000,
errorMessage: 'Sometimes You Just Have to Slow Down.',
id: (ctx) => ctx.ip,
headers: {
remaining: 'Rate-Limit-Remaining',
reset: 'Rate-Limit-Reset',
total: 'Rate-Limit-Total'
},
max: 100
}));
app.use(router.routes())
app.use(router.allowedMethods());
app.listen(process.env.PORT || 3000, (err) => {
if (err) {
return console.error('server could not start')
}
console.log('server is running')
})
protect.koa.sqlInjection([options])
Returns an Koa 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.koa.xss([options])
Returns an Koa 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
** The example app is making use of koa ratelimit module (https://github.com/koajs/ratelimit)
ratelimit([options])
db
redis connection instanceduration
of limit in milliseconds [3600000]errorMessage
custom error messageid
id to compare requests [ip]headers
custom header namesmax
max requests within duration
[2500]remaining
remaining number of requests ['X-RateLimit-Remaining'
]reset
reset timestamp ['X-RateLimit-Reset'
]total
total number of requests ['X-RateLimit-Limit'
]protect.koa.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
Security module for koa applications.
The npm package koa-protect receives a total of 180 weekly downloads. As such, koa-protect popularity was classified as not popular.
We found that koa-protect demonstrated a not healthy version release cadence and project activity because the last version was released 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
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.