Files
speckle-server/packages/server/modules/shared/utils/ip.js
T
Iain Sproat 122f4c731f feat(log): log the ip address if a user is not logged in (#1527)
- we do not log both the ip if the user is signed in, as this may be a privacy issue
- the ip is only logged if there is no associated user information
2023-04-13 14:57:07 +01:00

23 lines
546 B
JavaScript

const getIpFromRequest = (req) => {
let ip
try {
ip =
req.headers['cf-connecting-ip'] ||
req.headers['true-client-ip'] ||
req.headers['x-real-ip'] ||
req.headers['x-forwarded-for'] ||
req.ip ||
req.connection.remoteAddress ||
''
} catch {
ip = ''
}
const ignorePrefixes = ['192.168.', '10.', '127.', '172.1', '172.2', '172.3', '::']
for (const ipPrefix of ignorePrefixes)
if (ip.startsWith(ipPrefix) || ip === '') return null
return ip
}
module.exports = { getIpFromRequest }