diff options
| author | syuilo <Syuilotan@yahoo.co.jp> | 2023-01-24 17:51:09 +0900 |
|---|---|---|
| committer | syuilo <Syuilotan@yahoo.co.jp> | 2023-01-24 17:51:09 +0900 |
| commit | 8cab16c824f27a1ebc6b67c8012504eb58e50e20 (patch) | |
| tree | 06cdb7d6723562555482bbed46a3255e2f779648 /packages/backend/src/misc/get-ip-hash.ts | |
| parent | 13.2.1 (diff) | |
| download | misskey-8cab16c824f27a1ebc6b67c8012504eb58e50e20.tar.gz misskey-8cab16c824f27a1ebc6b67c8012504eb58e50e20.tar.bz2 misskey-8cab16c824f27a1ebc6b67c8012504eb58e50e20.zip | |
fix(server): /api/signin always returns 429 when request header x-forwarded-for contains client port
Fix #9408
Diffstat (limited to 'packages/backend/src/misc/get-ip-hash.ts')
| -rw-r--r-- | packages/backend/src/misc/get-ip-hash.ts | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/packages/backend/src/misc/get-ip-hash.ts b/packages/backend/src/misc/get-ip-hash.ts index 379325bb13..70e61aef8c 100644 --- a/packages/backend/src/misc/get-ip-hash.ts +++ b/packages/backend/src/misc/get-ip-hash.ts @@ -1,9 +1,14 @@ import IPCIDR from 'ip-cidr'; export function getIpHash(ip: string) { - // because a single person may control many IPv6 addresses, - // only a /64 subnet prefix of any IP will be taken into account. - // (this means for IPv4 the entire address is used) - const prefix = IPCIDR.createAddress(ip).mask(64); - return 'ip-' + BigInt('0b' + prefix).toString(36); + try { + // because a single person may control many IPv6 addresses, + // only a /64 subnet prefix of any IP will be taken into account. + // (this means for IPv4 the entire address is used) + 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); + } } |