• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

may215/koa-protect: Security module for koa applications

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

may215/koa-protect

开源软件地址:

https://github.com/may215/koa-protect

开源编程语言:

JavaScript 100.0%

开源软件介绍:

Koa-Protect by Altonotch

Known Vulnerabilities
KoaJs Slack

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.

Basic usage

npm i koa-protect --save  

With Express

const protect = require('koa-protect')  
const Koa = require('koa')  
const ratelimit = require('koa-ratelimit')
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')  
})  

API

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
    • default: false
    • prerequisite: you must have the body-parser module used before adding the protect middleware
  • options.loggerFunction: you can provide a logger function for the middleware to log attacks
    • default: 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
    • default: false
    • prerequisite: you must have the body-parser module used before adding the protect middleware
  • options.loggerFunction: you can provide a logger function for the middleware to log attacks
    • default: noop

** The example app is making use of koa ratelimit module (https://github.com/koajs/ratelimit)

ratelimit([options])

  • db redis connection instance
  • duration of limit in milliseconds [3600000]
  • errorMessage custom error message
  • id id to compare requests [ip]
  • headers custom header names
  • max 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.

Security Recommendations

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.

Other Aspects

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:

Resources

Dedicated WAF

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.




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap