fix(server): /api/signin always returns 429 when request header x-forwarded-for contains client port
Fix #9408
This commit is contained in:
parent
117ac53505
commit
8cab16c824
@ -1,9 +1,14 @@
|
|||||||
import IPCIDR from 'ip-cidr';
|
import IPCIDR from 'ip-cidr';
|
||||||
|
|
||||||
export function getIpHash(ip: string) {
|
export function getIpHash(ip: string) {
|
||||||
// because a single person may control many IPv6 addresses,
|
try {
|
||||||
// only a /64 subnet prefix of any IP will be taken into account.
|
// because a single person may control many IPv6 addresses,
|
||||||
// (this means for IPv4 the entire address is used)
|
// only a /64 subnet prefix of any IP will be taken into account.
|
||||||
const prefix = IPCIDR.createAddress(ip).mask(64);
|
// (this means for IPv4 the entire address is used)
|
||||||
return 'ip-' + BigInt('0b' + prefix).toString(36);
|
const prefix = IPCIDR.createAddress(ip).mask(64);
|
||||||
|
return 'ip-' + BigInt('0b' + prefix).toString(36);
|
||||||
|
} catch (e) {
|
||||||
|
const prefix = IPCIDR.createAddress(ip.replace(/:[0-9]+$/, '')).mask(64);
|
||||||
|
return 'ip-' + BigInt('0b' + prefix).toString(36);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user