Gathering detailed insights and metrics for express-ipfilter-secured
Gathering detailed insights and metrics for express-ipfilter-secured
Gathering detailed insights and metrics for express-ipfilter-secured
Gathering detailed insights and metrics for express-ipfilter-secured
A light-weight IP address based connection filtering system
npm install express-ipfilter-secured
Typescript
Module System
Node Version
NPM Version
JavaScript (96.35%)
HTML (2.67%)
CSS (0.99%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
109 Stars
153 Commits
44 Forks
10 Watchers
4 Branches
10 Contributors
Updated on Oct 09, 2024
Latest Version
0.3.3
Package Id
express-ipfilter-secured@0.3.3
Unpacked Size
127.75 kB
Size
21.80 kB
File Count
34
NPM Version
6.4.1
Node Version
10.14.1
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
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.
0.3.2
Recommended installation is with npm. To add node-ipfilter to your project, do:
npm install express-ipfilter-secured
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
allowedHeaders
list.
Blacklisting certain IP addresses, while allowing all other IPs:
1// Init dependencies 2var express = require('express'), 3 ipfilter = require('express-ipfilter-secured').IpFilter; 4 5// Blacklist the following IPs 6var ips = ['127.0.0.1']; 7 8// Create the server 9app.use(ipfilter(ips)); 10app.listen(3000);
Whitelisting certain IP addresses, while denying all other IPs:
1// Init dependencies 2// Init dependencies 3var express = require('express'), 4 ipfilter = require('express-ipfilter-secured').IpFilter; 5 6// Whitelist the following IPs 7var ips = ['127.0.0.1']; 8 9// Create the server 10app.use(ipfilter(ips, {mode: 'allow'})); 11 12module.exports = app;
Using CIDR subnet masks for ranges:
1var ips = ['127.0.0.1/24']; 2 3// Create the server 4app.use(ipfilter(ips, {mode: 'allow'})); 5 6module.exports = app;
Using IP ranges:
1var ips = [['127.0.0.1','127.0.0.10']]; 2 3// Create the server 4app.use(ipfilter(ips, {mode: 'allow'})); 5 6module.exports = app;
Using a function to get Ips:
1var ips = function() { return ['127.0.0.1']; }; 2 3// Create the server 4app.use(ipfilter(ips, {mode: 'allow'})); 5 6module.exports = app;
When an IP is denied, an IpDeniedError will be thrown by the middleware. If you do not handle the error, it will cause your app to crash due to an unhandled exception. Here is an example of how to handle the error, which can also be found in the example app:
if (app.get('env') === 'development') {
app.use(function(err, req, res, _next) {
console.log('Error handler', err);
if(err instanceof IpDeniedError){
res.status(401);
}else{
res.status(err.status || 500);
}
res.render('error', {
message: 'You shall not pass',
error: err
});
});
}
You will need to require the IpDeniedError
type in order to handle it.
Property | Description | Type | Default |
---|---|---|---|
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 | [] |
detectIp | define a custom function that takes an Express request object and returns an IP address to test against | function | built-in detection |
A note on detectIp
If you need to parse an IP address in a way that is not supported by default, you can write your own parser and pass that to ipfilter
.
function customDetection(req){
var ipAddress;
ipAddress = req.connection.remoteAddress.replace(/\//g, '.');
return ipAddress;
}
ipfilter(ids, {detectIp: customDetection});
See the CONTRIBUTING.MD
document for more information on contributing.
You can run grunt
to build the source. This will run eslint
and babel
against src/ipfilter.js
.
There is an included example
project that will load the package from the local build for testing.
Run tests by using
grunt test
This will run eslint
,babel
, and mocha
and output coverage data into coverage
. Any pull request you submit needs to be accompanied by a test.
0.3.3
0.3.2
src/ipfulter.js
for tests to pass0.3.1
0.3.0
0.2.6
0.2.5
status
and statusCode
to the IpDeniedError object, which both equal 403
.0.2.4
0.2.3
0.2.2
0.2.1
0.2.0
allowedHeaders
to support those header-based IP addresses.IpFilter
, i.e. var ipfilter = require('express-ipfilter-secured').IpFilter;
var IpDeniedError = require('express-ipfilter-secured').IpDeniedError;
0.1.1
0.1.0
res.send
when a failure occurs to allow for different formats of errorMessage
0.0.25
0.0.24
0.0.23
0.0.22
0.0.20
0.0.19
0.0.18
0.0.16
0.0.15
0.0.14
0.0.12
0.0.11
0.0.10
0.0.9
0.0.8
0.0.7
0.0.6
0.0.5
0.0.4
0.0.1
BaM Interactive - code.bamideas.com
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
Found 6/13 approved changesets -- score normalized to 4
Reason
project is archived
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More