From fb3fe17c2824e62a731270257746b9b214d17912 Mon Sep 17 00:00:00 2001 From: Louis Lam Date: Mon, 1 Aug 2022 15:42:58 +0800 Subject: [PATCH] Fix getClientIP Co-authored-by: Mateusz Hajder <6783135+mhajder@users.noreply.github.com> --- server/uptime-kuma-server.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/server/uptime-kuma-server.js b/server/uptime-kuma-server.js index 67b6ed0a3..98de65a43 100644 --- a/server/uptime-kuma-server.js +++ b/server/uptime-kuma-server.js @@ -131,14 +131,18 @@ class UptimeKumaServer { } async getClientIP(socket) { - const clientIP = socket.client.conn.remoteAddress.replace(/^.*:/, ""); + let clientIP = socket.client.conn.remoteAddress; + + if (clientIP === undefined) { + clientIP = ""; + } if (await Settings.get("trustProxy")) { return socket.client.conn.request.headers["x-forwarded-for"] || socket.client.conn.request.headers["x-real-ip"] - || clientIP; + || clientIP.replace(/^.*:/, ""); } else { - return clientIP; + return clientIP.replace(/^.*:/, ""); } } }