Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function ensureInternalAccess (req, res, next) {
let ip = req.ip || req.connection.remoteAddress || req.socket.remoteAddress || req.connection.socket.remoteAddress
ip = ip.replace('::ffff:', '')
let serverIp = ipLib.address('public', 'ipv4')
if (ip === serverIp || (rangeCheck.validIp(ip) && rangeCheck.inRange(ip, config.internal_ip))) {
next()
} else {
logger.warn(ip, 'is not an internal ip. Access denied')
res.end()
}
}