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

addr

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

addr - npm Package Compare versions

Comparing version 0.0.0 to 1.0.0

2

examples/simple.js
var addr = require('../')
, http = require('http')
, port = 3000
, proxies = ['127.0.0.1', '1.2.3.4']
, proxies = ['127.0.0.1']
;

@@ -6,0 +6,0 @@

@@ -10,15 +10,7 @@

if (proxies && proxies.indexOf(req.connection.remoteAddress) === -1) {
return false;
// Don't honor the x-forwarded-for header if request is not from a trusted
// source.
return req.connection.remoteAddress;
}
var addrs = req.headers['x-forwarded-for'].split(/\s?,\s?/);
var ip = addrs.shift();
if (proxies) {
var proxy;
while (proxy = addrs.pop()) {
if (proxies.indexOf(proxy) === -1) {
return false;
}
}
}
return ip;
return req.headers['x-forwarded-for'].split(/\s?,\s?/).shift();
};
{
"name": "addr",
"version": "0.0.0",
"version": "1.0.0",
"description": "Get the remote address of a request, with reverse-proxy support",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "make test"
},

@@ -9,0 +9,0 @@ "repository": {

@@ -17,3 +17,4 @@ addr

- `proxes`: an array of IP addresses of trusted proxies. If specified and
the request doesn't come from one of these addresses, `false` will be returned.
the request doesn't come from one of these addresses, the `X-Forwarded-For`
header will not be honored.
- Returns: Remote IP address of the request, taken from the `X-Forwarded-For`

@@ -29,3 +30,3 @@ header if it exists and the request is coming from a trusted proxy.

, port = 3000
, proxies = ['127.0.0.1', '1.2.3.4']
, proxies = ['127.0.0.1']
;

@@ -32,0 +33,0 @@

@@ -13,3 +13,3 @@ var addr = require('../')

res.writeHead(200, {'Content-Type': 'application/json'});
var proxies = (req.url === '/not-trusted') ? ['127.0.0.1', '1.2.3.4'] : null;
var proxies = (req.url === '/not-trusted') ? '127.0.0.1' : null;
res.write(JSON.stringify({addr: addr(req, proxies)}));

@@ -33,9 +33,2 @@ res.end();

});
it('returns false if proxy isn\'t trusted', function(done) {
request({url: baseUrl + '/not-trusted', headers: {'X-Forwarded-For': '55.55.55.55, 1.2.3.4,5.6.7.8'}, json: true}, function(err, res, data) {
assert.equal(res.statusCode, 200);
assert.strictEqual(data.addr, false);
done();
});
});
});
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