From b955d1981191b0ec43be671215232078d6bb25ca Mon Sep 17 00:00:00 2001 From: holly Date: Fri, 3 Sep 2021 21:13:17 +0100 Subject: [PATCH] read cf requestee IP from the headers first --- server/loginHandler.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/server/loginHandler.js b/server/loginHandler.js index dac781b..319919a 100644 --- a/server/loginHandler.js +++ b/server/loginHandler.js @@ -25,7 +25,14 @@ module.exports = async function(req, res, loginInfo) { } // Get users IP for getting location - let requestIP = req.get('X-Real-IP'); + // Get cloudflare requestee IP first + let requestIP = req.get("cf-connecting-ip"); + + // Get IP of requestee since we are probably behind a reverse proxy + if (requestIP == null) + requestIP = req.get("X-Real-IP"); + + // Just get the requestee IP (we are not behind a reverse proxy) if (requestIP == null) requestIP = req.remote_addr;