mirror of
https://github.com/imputnet/cobalt.git
synced 2026-11-03 00:04:55 +00:00
api: bind session tokens to ip hash
This commit is contained in:
parent
bf5937e336
commit
1f768df4ec
3 changed files with 22 additions and 16 deletions
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue