request-ip
Advanced tools
Comparing version 1.2.2 to 1.2.3
# Change Log | ||
## [Unreleased](https://github.com/pbojinov/request-ip/tree/HEAD) | ||
[Full Changelog](https://github.com/pbojinov/request-ip/compare/1.2.2...HEAD) | ||
**Closed issues:** | ||
- Are there any security concerns when saving the IP directly to a database? [\#16](https://github.com/pbojinov/request-ip/issues/16) | ||
- I'm not getting local host ip address 127.0.0.1 [\#14](https://github.com/pbojinov/request-ip/issues/14) | ||
## [1.2.2](https://github.com/pbojinov/request-ip/tree/1.2.2) (2016-01-27) | ||
[Full Changelog](https://github.com/pbojinov/request-ip/compare/1.2.1...1.2.2) | ||
## [1.2.1](https://github.com/pbojinov/request-ip/tree/1.2.1) (2016-01-27) | ||
@@ -4,0 +16,0 @@ [Full Changelog](https://github.com/pbojinov/request-ip/compare/1.2.0...1.2.1) |
11
index.js
@@ -47,7 +47,9 @@ /** | ||
// x-forwarded-for | ||
// (typically when your node app is behind a load-balancer (eg. AWS ELB) or proxy) | ||
else if (forwardedForAlt) { | ||
// x-forwarded-for header is more common | ||
// it may return multiple IP addresses in the format: | ||
// x-forwarded-for may return multiple IP addresses in the format: | ||
// "client IP, proxy 1 IP, proxy 2 IP" | ||
// we pick the first one | ||
// Therefore, the right-most IP address is the IP address of the most recent proxy | ||
// and the left-most IP address is the IP address of the originating client. | ||
// source: http://docs.aws.amazon.com/elasticloadbalancing/latest/classic/x-forwarded-headers.html | ||
var forwardedIps = forwardedForAlt.split(','); | ||
@@ -60,4 +62,3 @@ ipAddress = forwardedIps[0]; | ||
else if (realIp) { | ||
// alternative to x-forwarded-for | ||
// used by some proxies | ||
// alternative to x-forwarded-for, used by some proxies | ||
ipAddress = realIp; | ||
@@ -64,0 +65,0 @@ } |
{ | ||
"name": "request-ip", | ||
"version": "1.2.2", | ||
"version": "1.2.3", | ||
"description": "A small node.js module to retrieve the request's IP address", | ||
@@ -15,4 +15,6 @@ "main": "index.js", | ||
"keywords": [ | ||
"request ip", | ||
"ip", | ||
"address", | ||
"request", | ||
"client", | ||
@@ -24,4 +26,3 @@ "header", | ||
"connection.remoteAddress", | ||
"middleware", | ||
"request" | ||
"middleware" | ||
], | ||
@@ -41,4 +42,3 @@ "author": "Petar Bojinov <petarbojinov@gmail.com>", | ||
}, | ||
"dependencies": { | ||
} | ||
"dependencies": {} | ||
} |
@@ -257,1 +257,39 @@ var http = require('http'); | ||
}); | ||
test('android request to AWS EBS app (x-forwarded-for)', function(t) { | ||
t.plan(1); | ||
// 172.x.x.x and 192.x.x.x. are considered "private IP subnets" | ||
// so we want to library to return "107.77.213.113" as the IP address | ||
// https://tools.ietf.org/html/rfc1918#section-3 | ||
var expectedResult = '107.77.213.113'; | ||
var options = { | ||
url: '', | ||
headers: { | ||
"host": "[redacted]", | ||
"x-real-ip": "172.31.41.116", | ||
"x-forwarded-for": "107.77.213.113, 172.31.41.116", | ||
"accept-encoding": "gzip", | ||
"user-agent": "okhttp/3.4.1", | ||
"x-forwarded-port": "443", | ||
"x-forwarded-proto": "https" | ||
} | ||
}; | ||
// create new server for each test so we can easily close it after the test is done | ||
// prevents tests from hanging and competing against closing a global server | ||
var server = new serverFactory(); | ||
server.listen(0, serverInfo.host); | ||
server.on('listening', function() { | ||
options.url = 'http://' + serverInfo.host + ':' + server.address().port; | ||
request(options, callback); | ||
}); | ||
function callback(error, response, body) { | ||
if (!error && response.statusCode === 200) { | ||
// ip address should be equal to the first "x-forwarded-for" value | ||
// console.log(body) | ||
// t.comment(body) | ||
t.equal(expectedResult, body); | ||
server.close(); | ||
} | ||
} | ||
}); |
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
24549
411