normalize socket IP format

This commit is contained in:
Matteo Mekhail
2026-02-23 13:12:42 +11:00
parent 0295041cda
commit 8489927b67

View File

@@ -132,11 +132,13 @@ function getClientIp(req: Request, server: Bun.Server<WsData>): string {
const xff = req.headers.get("x-forwarded-for");
if (xff) {
const rightmost = xff.split(",").at(-1)?.trim();
if (rightmost) return rightmost;
if (rightmost && !isPrivateIp(rightmost)) {
return rightmost.startsWith("::ffff:") ? rightmost.slice(7) : rightmost;
}
}
}
return socketIp;
return socketIp.startsWith("::ffff:") ? socketIp.slice(7) : socketIp;
}
function isRateLimited(key: string, limit: number, windowMs: number): boolean {