1
0
Fork 0
forked from svrjs/svrjs

Dropped support for unused SVR.JS-specific X-SVR-JS-Client header (use X-Forwarded-For header instead)

This commit is contained in:
Dorian Niemiec 2023-09-02 18:33:09 +02:00
parent 9b27bacf25
commit 1637e87550

60
svr.js
View file

@ -2419,25 +2419,7 @@ if (!cluster.isPrimary) {
var reqip = ""; var reqip = "";
var oldport = ""; var oldport = "";
var oldip = ""; var oldip = "";
if (req.headers["x-svr-js-client"] != undefined && enableIPSpoofing) { if (req.headers["x-forwarded-for"] != undefined && enableIPSpoofing) {
var kl = req.headers["x-svr-js-client"].split(":");
reqport = kl.pop();
reqip = kl.join(":");
try {
oldport = req.socket.remotePort;
oldip = req.socket.remoteAddress;
req.socket.realRemotePort = reqport;
req.socket.realRemoteAddress = reqip;
req.socket.originalRemotePort = oldport;
req.socket.originalRemoteAddress = oldip;
res.socket.realRemotePort = reqport;
res.socket.realRemoteAddress = reqip;
res.socket.originalRemotePort = oldport;
res.socket.originalRemoteAddress = oldip;
} catch (err) {
//Nevermind...
}
} else if (req.headers["x-forwarded-for"] != undefined && enableIPSpoofing) {
reqport = null; reqport = null;
reqip = req.headers["x-forwarded-for"].split(",")[0].replace(/ /g, ""); reqip = req.headers["x-forwarded-for"].split(",")[0].replace(/ /g, "");
if (reqip.indexOf(":") == -1) reqip = "::ffff:" + reqip; if (reqip.indexOf(":") == -1) reqip = "::ffff:" + reqip;
@ -3351,25 +3333,7 @@ if (!cluster.isPrimary) {
var reqip = ""; var reqip = "";
var oldport = ""; var oldport = "";
var oldip = ""; var oldip = "";
if (req.headers["x-svr-js-client"] != undefined && enableIPSpoofing) { if (req.headers["x-forwarded-for"] != undefined && enableIPSpoofing) {
var kl = req.headers["x-svr-js-client"].split(":");
reqport = kl.pop();
reqip = kl.join(":");
try {
oldport = req.socket.remotePort;
oldip = req.socket.remoteAddress;
req.socket.realRemotePort = reqport;
req.socket.realRemoteAddress = reqip;
req.socket.originalRemotePort = oldport;
req.socket.originalRemoteAddress = oldip;
res.socket.realRemotePort = reqport;
res.socket.realRemoteAddress = reqip;
res.socket.originalRemotePort = oldport;
res.socket.originalRemoteAddress = oldip;
} catch (err) {
//Address setting failed
}
} else if (req.headers["x-forwarded-for"] != undefined && enableIPSpoofing) {
reqport = null; reqport = null;
reqip = req.headers["x-forwarded-for"].split(",")[0].replace(/ /g, ""); reqip = req.headers["x-forwarded-for"].split(",")[0].replace(/ /g, "");
if (reqip.indexOf(":") == -1) reqip = "::ffff:" + reqip; if (reqip.indexOf(":") == -1) reqip = "::ffff:" + reqip;
@ -3848,25 +3812,7 @@ if (!cluster.isPrimary) {
var reqip = ""; var reqip = "";
var oldport = ""; var oldport = "";
var oldip = ""; var oldip = "";
if (req.headers["x-svr-js-client"] != undefined && enableIPSpoofing) { if (req.headers["x-forwarded-for"] != undefined && enableIPSpoofing) {
var kl = req.headers["x-svr-js-client"].split(":");
reqport = kl.pop();
reqip = kl.join(":");
try {
oldport = req.socket.remotePort;
oldip = req.socket.remoteAddress;
req.socket.realRemotePort = reqport;
req.socket.realRemoteAddress = reqip;
req.socket.originalRemotePort = oldport;
req.socket.originalRemoteAddress = oldip;
res.socket.realRemotePort = reqport;
res.socket.realRemoteAddress = reqip;
res.socket.originalRemotePort = oldport;
res.socket.originalRemoteAddress = oldip;
} catch (err) {
//Nevermind...
}
} else if (req.headers["x-forwarded-for"] != undefined && enableIPSpoofing) {
reqport = null; reqport = null;
reqip = req.headers["x-forwarded-for"].split(",")[0].replace(/ /g, ""); reqip = req.headers["x-forwarded-for"].split(",")[0].replace(/ /g, "");
if (reqip.indexOf(":") == -1) reqip = "::ffff:" + reqip; if (reqip.indexOf(":") == -1) reqip = "::ffff:" + reqip;