Correctly handle multiple IPs in X-Forwarded-For (#2177)

Co-authored-by: Louis Lam <louislam@users.noreply.github.com>
This commit is contained in:
Ben Scobie
2022-10-05 16:45:21 +01:00
committed by GitHub
parent 528a615fb2
commit c28d8ddff9
3 changed files with 87 additions and 4 deletions

View File

@@ -138,7 +138,9 @@ class UptimeKumaServer {
}
if (await Settings.get("trustProxy")) {
return socket.client.conn.request.headers["x-forwarded-for"]
const forwardedFor = socket.client.conn.request.headers["x-forwarded-for"];
return (typeof forwardedFor === "string" ? forwardedFor.split(",")[0].trim() : null)
|| socket.client.conn.request.headers["x-real-ip"]
|| clientIP.replace(/^.*:/, "");
} else {