From bf9532ac395d54318aef61c5fbb12841451bb49d Mon Sep 17 00:00:00 2001 From: Tom <58078313+reed-tom@users.noreply.github.com> Date: Mon, 11 Sep 2023 14:25:19 -0400 Subject: [PATCH] added multiple tests for IP headers (#49) --- routes/public/stats/index.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/routes/public/stats/index.js b/routes/public/stats/index.js index a8bfba8..52298b4 100644 --- a/routes/public/stats/index.js +++ b/routes/public/stats/index.js @@ -31,8 +31,13 @@ module.exports = (baseRoute, middleWare, router) => { */ try { if (!common.isHostAllowed(req, res)) return; + console.log("HEADERS" + JSON.stringify(req.headers), "remoteAddress" + req.connection.remoteAddress, "remotePort" + req.connection.remotePort, "localAddress" + req.connection.localAddress); // IP FROM PROXY - const ip = req.headers["proxy-ip"] === undefined ? "LOCAL_DEBUGGING" : req.headers["proxy-ip"]; + let ip = req.headers["x-real-ip"]; + if (ip === undefined) ip = req.headers["proxy-ip"]; + if (ip === undefined) ip = req.headers["x-forwarded-for"]; + if (ip === undefined) ip = req.connection.remoteAddress; + if (ip === "::1") ip = "LOCAL_DEBUGGING"; // INSERT APP STAT appStats.insertAppStat(req.params.appName, req.params.actionType, req.params.description, ip);