Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
ipProxyMiddleware(socket, next) {
if (!socket.context) socket.context = {};
try {
socket.handshake.connection = {
remoteAddress: socket.handshake.address
};
socket.context.ipAddress = proxyaddr(
socket.handshake,
this.proxyTrustFn
);
if (!socket.context.ipAddress) {
throw new Error(
`Assertion failed: unexpected IP ${socket.context.ipAddress}`
);
}
} catch (error) {
LOGGER.warn('Rejecting socket - proxyaddr failed: %s', error);
next(new Error('Could not determine IP address'));
return;
}
if (isTorExit(socket.context.ipAddress)) {
public get ip() {
return proxyAddr(this, SETTINGS["trust.proxy"]);
}
function readProxyHeaders(trustFn, req, res, next) {
const forwardedIP = proxyaddr(req, trustFn);
if (forwardedIP !== req.ip) {
req.realIP = forwardedIP;
req.realProtocol = getForwardedProto(req);
} else {
req.realIP = req.ip;
req.realProtocol = req.protocol;
}
next();
}
public ip (): string {
const ipFn = this._config.getIp
if (typeof (ipFn) === 'function') {
return ipFn(this)
}
return proxyaddr(this.request, this._config.trustProxy)
}