A light-weight IP address based filtering system
This package provides easy IP based access control. This can be achieved either by blacklisting certain IPs and whitelisting all others, or whitelisting certain IPs and blacklisting all others.
Recommended installation is with npm. To add node-ipfilter to your project, do:
npm install express-ipfilter
NOTE: Starting with version 0.1.0, allow forwarded IP addresses through headers (forward, Cloudflare, Codio) are disabled by default. You must explicitly enable them by adding them to the
Blacklisting certain IP addresses, while allowing all other IPs:
// Init dependenciesvar express =ipfilter = IpFilter;// Blacklist the following IPsvar ips = '127.0.0.1';// Create the serverapp;app;
Whitelisting certain IP addresses, while denying all other IPs:
// Init dependencies// Init dependenciesvar express =ipfilter = IpFilter;// Whitelist the following IPsvar ips = '127.0.0.1';// Create the serverapp;moduleexports = app;
Using CIDR subnet masks for ranges:
var ips = '127.0.0.1/24';// Create the serverapp;moduleexports = app;
Using IP ranges:
var ips = '127.0.0.1''127.0.0.10';// Create the serverapp;moduleexports = app;
See the example app for an example of how to handle errors.
|mode||whether to deny or allow to the IPs provided||string||deny|
|log||console log actions||boolean||true|
|logLevel||level of logging (all,deny,allow)||string||all|
|allowedHeaders||an array of strings for header names that are acceptable for retrieving an IP address||array|||
|excluding||routes that should be excluded from ip filtering||array|||
You can run
grunt to build the source. This will run
There is an included
example project that will load the package from the local build for testing.
Run tests by using
This will run
mocha and output coverage data into
coverage. Any pull request you submit needs to be accompanied by a test.
allowedHeadersto support those header-based IP addresses.
var ipfilter = require('express-ipfilter').IpFilter;
var IpDeniedError = require('express-ipfilter').IpDeniedError;
res.sendwhen a failure occurs to allow for different formats of
BaM Interactive - code.bamideas.com