Fix incorrect parsing of x-forwarded-for in webserver.ipForRequest
This commit is contained in:
parent
d4885951fb
commit
2a507fcac5
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue