Comparing version 0.0.0 to 1.0.0
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 @@ |
16
index.js
@@ -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(); | ||
}); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
1
44
3570
56