api: bind session tokens to ip hash

This commit is contained in:
jj
2025-03-30 17:03:52 +00:00
parent bf5937e336
commit 1f768df4ec
3 changed files with 22 additions and 16 deletions

View File

@@ -82,14 +82,13 @@ export function normalizeRequest(request) {
));
}
export function getIP(req) {
export function getIP(req, prefix = 56) {
const strippedIP = req.ip.replace(/^::ffff:/, '');
const ip = ipaddr.parse(strippedIP);
if (ip.kind() === 'ipv4') {
return strippedIP;
}
const prefix = 56;
const v6Bytes = ip.toByteArray();
v6Bytes.fill(0, prefix / 8);