Fix incorrect parsing of x-forwarded-for in webserver.ipForRequest

This commit is contained in:
calzoneman 2014-04-17 00:03:32 -05:00
parent d4885951fb
commit 2a507fcac5
1 changed files with 10 additions and 3 deletions

View File

@ -37,11 +37,18 @@ function ipForRequest(req) {
var ip = req.ip;
if (ip === "127.0.0.1" || ip === "::1") {
var xforward = req.header("x-forwarded-for");
if (typeof xforward !== "string" || !net.isIP(xforward)) {
return ip;
if (typeof xforward !== "string") {
xforward = [];
} else {
return xforward;
xforward = xforward.split(",");
}
for (var i = 0; i < xforward.length; i++) {
if (net.isIP(xforward[i])) {
return xforward[i];
}
}
return ip;
}
return ip;
}