mirror of https://github.com/calzoneman/sync.git
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;
|
var ip = req.ip;
|
||||||
if (ip === "127.0.0.1" || ip === "::1") {
|
if (ip === "127.0.0.1" || ip === "::1") {
|
||||||
var xforward = req.header("x-forwarded-for");
|
var xforward = req.header("x-forwarded-for");
|
||||||
if (typeof xforward !== "string" || !net.isIP(xforward)) {
|
if (typeof xforward !== "string") {
|
||||||
return ip;
|
xforward = [];
|
||||||
} else {
|
} 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;
|
return ip;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue