All Projects → tunnckoCore → koa-ip-filter

tunnckoCore / koa-ip-filter

Licence: MIT license
koa middleware to filter request IPs or custom ID with glob patterns, array, string, regexp or matcher function. Support custom 403 Forbidden message and custom ID.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to koa-ip-filter

Egg
🥚 Born to build better enterprise frameworks and apps with Node.js & Koa
Stars: ✭ 17,616 (+76491.3%)
Mutual labels:  koa, koa-middleware
dir-glob
Convert directories to glob compatible strings
Stars: ✭ 41 (+78.26%)
Mutual labels:  matching, glob
matchering-web
🎚️ Self-Hosted LANDR / eMastered Alternative
Stars: ✭ 25 (+8.7%)
Mutual labels:  matching, limiter
Is Glob
If you use globs, this will make your code faster. Returns `true` if the given string looks like a glob pattern or an extglob pattern. This makes it easy to create code that only uses external modules like node-glob when necessary, resulting in much faster code execution and initialization time, and a better user experience. 55+ million downloads.
Stars: ✭ 63 (+173.91%)
Mutual labels:  matching, glob
koa-subdomain
Simple and lightweight Koa middleware to handle multilevel and wildcard subdomains
Stars: ✭ 23 (+0%)
Mutual labels:  koa, koa-middleware
Globby
User-friendly glob matching
Stars: ✭ 1,864 (+8004.35%)
Mutual labels:  matching, glob
matchering-cli
🎚️ Simple Matchering 2.0 Command Line Application
Stars: ✭ 28 (+21.74%)
Mutual labels:  matching, limiter
koa-vue-view
A Koa view engine which renders Vue components on server.
Stars: ✭ 29 (+26.09%)
Mutual labels:  koa, koa-middleware
Koa Ip
Ip filter middleware for koa, support whitelist and blacklist.
Stars: ✭ 37 (+60.87%)
Mutual labels:  koa, ip
Koa Proxy
Proxy middleware for koa
Stars: ✭ 221 (+860.87%)
Mutual labels:  koa
IPpy
🚀 Ping IP addresses and domains in parallel to find the accessible and inaccessible ones.
Stars: ✭ 54 (+134.78%)
Mutual labels:  ip
Openapi Backend
Build, Validate, Route, Authenticate and Mock using OpenAPI
Stars: ✭ 216 (+839.13%)
Mutual labels:  koa
Koa Websocket
Light wrapper around Koa providing a websocket middleware handler that is koa-route compatible.
Stars: ✭ 224 (+873.91%)
Mutual labels:  koa
matched
Glob matching with support for multiple patterns and negation. Use `~` in cwd to find files in user home, or `@` for global npm modules.
Stars: ✭ 25 (+8.7%)
Mutual labels:  glob
Roa
async web framework inspired by koajs, lightweight but powerful.
Stars: ✭ 221 (+860.87%)
Mutual labels:  koa
bunjil
A GraphQL bastion server with schema merging, authentication and authorization with Policy Based Access Control
Stars: ✭ 25 (+8.7%)
Mutual labels:  koa
Koa Webpack Middleware
webpack dev&hot middleware for koa2
Stars: ✭ 215 (+834.78%)
Mutual labels:  koa
Graphql Demo
🎉Koa + GraphQL + Apollo-Server demo
Stars: ✭ 215 (+834.78%)
Mutual labels:  koa
pupflare
A webpage proxy that request through Chromium (puppeteer) - can be used to bypass Cloudflare anti bot / anti ddos on any application (like curl)
Stars: ✭ 183 (+695.65%)
Mutual labels:  koa
koa-plus
The Koa framework extended for APIs. Optimized for security, scalability, and productivity.
Stars: ✭ 17 (-26.09%)
Mutual labels:  koa

koa-ip-filter npmjs.com The MIT License npm downloads

Middleware for koa that filters IPs against glob patterns, RegExp, string or array of globs. Support custom 403 Forbidden message and custom ID.

code climate standard code style travis build status coverage status dependency status

Install

npm i koa-ip-filter --save

Features

  • custom message when 403 Forbidden response, through opts.forbidden
  • custom identifier different than default this.ip, through opts.id
    • you may want to add opts.strict: false if it's not IP
  • filter IP using glob patterns, regexp, string, array or function
  • blacklist with negative glob patterns, whitelist with positive
  • would restrict all to 403 Forbidden that not match to filter

Notice: In the next middleware you will have this.filter method which is ip-filter and this.identifier - the IP/ID that passed the given filter

Usage

For more use-cases see the tests

const koaIpFilter = require('koa-ip-filter')

koaIpFilter

Filtering incoming request with glob patterns array, regexp, string or matcher function

Params

  • options {Object}
    • id {Function}: custom identifier, defaults to this.ip
    • strict {Boolean}: to throw when not valid IPv4/IPv6? default true
    • filter {Array|String|RegExp|Function}: black/white list filter
    • forbidden {String|Function}: custom message when 403 Forbidden response
  • returns {GeneratorFunction}

Example

'use strict'

var koa = require('koa')
var ipFilter = require('koa-ip-filter')
var helloWorld = require('koa-hello-world')

var app = koa()

app
.use(ipFilter({
  forbidden: '403: Get out of here!',
  filter: ['127.??.6*.12', '!1.2.*.4']
}))
.use(helloWorld())

app.listen(1234)
console.log('koa server start listening on http://localhost:1234')

// if your IP is `127.43.65.12` you will see `Hello World`
// otherwise you will see `403: Get out of here!`

One more example

If you want to allow all IPs, but want to restrict only some range

'use strict'

var koa = require('koa')
var ipFilter = require('koa-ip-filter')
var helloWorld = require('koa-hello-world')

var app = koa()

app
.use(ipFilter({
  forbidden: '403: Get out of here!',
  filter: ['*', '!213.15.*']
}))
.use(helloWorld())

app.listen(1234)
console.log('koa server start listening on http://localhost:1234')

// only user with IP starting with `213.15.*` 
// will see the message `403: Get out of here!`

Related

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
But before doing anything, please read the CONTRIBUTING.md guidelines.

Charlike Make Reagent new message to charlike freenode #charlike

tunnckoCore.tk keybase tunnckoCore tunnckoCore npm tunnckoCore twitter tunnckoCore github

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].