Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

express-ipfilter

Package Overview
Dependencies
Maintainers
1
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

express-ipfilter - npm Package Compare versions

Comparing version 0.0.6 to 0.0.9

18

lib/ipfilter.js

@@ -11,3 +11,3 @@ /*!

*/
var _ = require('underscore')
var _ = require('lodash')
, iputil = require('ip')

@@ -51,2 +51,3 @@ , Netmask = require('netmask').Netmask;

, cidr: false
, ranges: false
});

@@ -90,2 +91,17 @@

}
}else if(settings.ranges){
var filteredSet = _.filter(ips,function(ipSet){
if(ipSet.length > 1){
var startIp = iputil.toLong(ipSet[0]);
var endIp = iputil.toLong(ipSet[1]);
var longIp = iputil.toLong(ip);
return longIp >= startIp && longIp <= endIp;
}else{
return ip == ipSet[0];
}
});
allowedIp = (mode == 'allow' && filteredSet.length > 0);
notBannedIp = (mode == 'deny' && filteredSet.length === 0);
isPrivateIpOkay = settings.allowPrivateIPs && iputil.isPrivate(ip) && !(mode == 'deny' && filteredSet.length > 0);
}else{

@@ -92,0 +108,0 @@ allowedIp = (mode == 'allow' && ips.indexOf(ip) !== -1);

6

package.json
{
"name": "express-ipfilter",
"description": "A light-weight IP address based filtering system",
"version": "0.0.6",
"version": "0.0.9",
"author": "BaM Interactive",
"dependencies": {
"underscore": "1.3.3",
"netmask": "~1.0.4",
"ip": "~0.3.0"
"ip": "~0.3.0",
"lodash": "~2.4.1"
},

@@ -11,0 +11,0 @@ "devDependencies": {

@@ -9,3 +9,3 @@ IP Filter: A light-weight IP address based filtering system

## Version
0.0.6
0.0.9

@@ -57,9 +57,2 @@ ## Installation

```javascript
// Init dependencies
var express = require('express')
, ipfilter = require('ipfilter')
, app = express.createServer()
;
// Blacklist the following IPs
var ips = ['127.0.0.1/24'];

@@ -72,4 +65,26 @@

Using IP ranges:
```javascript
var ips = [['127.0.0.1','127.0.0.10']];
// Create the server
app.use(ipfilter(ips, {mode: 'allow'}));
app.listen(3000);
```
## Changelog
0.0.9
* Fixing deploy issues
0.0.8
* Auto deploys for npm
0.0.7
* Add support ip ranges.
0.0.6

@@ -76,0 +91,0 @@

@@ -236,1 +236,160 @@ /*global describe, it, after, before, beforeEach, afterEach*/

});
describe('using ranges',function(){
describe('enforcing whitelist restrictions',function(){
beforeEach(function(){
// Ip range: 127.0.0.1 - 127.0.0.14
this.ipfilter = ipfilter([ ['127.0.0.1','127.0.0.3'] ], { ranges: true, log: false, mode: 'allow' });
this.req = {
session: {},
headers: [],
connection: {
remoteAddress: ''
}
};
});
it('should allow whitelisted ips', function( done ){
this.req.connection.remoteAddress = '127.0.0.1';
this.ipfilter( this.req, {}, function(){
done();
});
});
it('should allow whitelisted forwarded ips', function( done ){
this.req.headers['x-forwarded-for'] = '127.0.0.1';
this.ipfilter( this.req, {}, function(){
done();
});
});
it('should deny all non-whitelisted ips', function( done ){
this.req.connection.remoteAddress = '127.0.0.17';
var res = {
end: function(msg){
assert.equal( 401, res.statusCode );
done();
}
};
this.ipfilter( this.req, res, function(){});
});
it('should deny all non-whitelisted forwarded ips', function( done ){
this.req.headers['x-forwarded-for'] = '127.0.0.17';
var res = {
end: function(msg){
assert.equal( 401, res.statusCode );
done();
}
};
this.ipfilter( this.req, res, function(){});
});
});
describe('enforcing ip restrictions with only one ip in the range',function(){
beforeEach(function(){
// Ip range: 127.0.0.1 - 127.0.0.14
this.ipfilter = ipfilter([ ['127.0.0.1'] ], { ranges: true, log: false, mode: 'allow' });
this.req = {
session: {},
headers: [],
connection: {
remoteAddress: ''
}
};
});
it('should allow whitelisted ips', function( done ){
this.req.connection.remoteAddress = '127.0.0.1';
this.ipfilter( this.req, {}, function(){
done();
});
});
it('should deny all non-whitelisted ips', function( done ){
this.req.connection.remoteAddress = '127.0.0.17';
var res = {
end: function(msg){
assert.equal( 401, res.statusCode );
done();
}
};
this.ipfilter( this.req, res, function(){});
});
});
describe('enforcing IP address blacklist restrictions', function(){
beforeEach(function(){
this.ipfilter = ipfilter([ ['127.0.0.1','127.0.0.3'] ], { ranges: true, log: false });
this.req = {
session: {},
headers: [],
connection: {
remoteAddress: ''
}
};
});
it('should allow all non-blacklisted ips', function( done ){
this.req.connection.remoteAddress = '127.0.0.17';
this.ipfilter( this.req, {}, function(){
done();
});
});
it('should allow all non-blacklisted forwarded ips', function( done ){
this.req.headers['x-forwarded-for'] = '127.0.0.17';
this.ipfilter( this.req, {}, function(){
done();
});
});
it('should deny all blacklisted ips', function( done ){
this.req.connection.remoteAddress = '127.0.0.1';
var res = {
end: function(msg){
assert.equal( 401, res.statusCode );
done();
}
};
this.ipfilter( this.req, res, function(){});
});
it('should deny all blacklisted forwarded ips', function( done ){
this.req.headers['x-forwarded-for'] = '127.0.0.1';
var res = {
end: function(msg){
assert.equal( 401, res.statusCode );
done();
}
};
this.ipfilter( this.req, res, function(){});
});
});
describe("enforcing private ip restrictions",function(){
beforeEach(function(){
this.ipfilter = ipfilter([ ['127.0.0.1','127.0.0.3'] ], { ranges: true, log: false, allowPrivateIPs: true });
this.req = {
session: {},
headers: [],
connection: {
remoteAddress: ''
}
};
});
it('should allow all private ips', function( done ){
this.req.connection.remoteAddress = '10.0.0.0';
this.ipfilter( this.req, {}, function(){
done();
});
});
});
});

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc