mirror of
https://github.com/louislam/uptime-kuma.git
synced 2024-11-25 19:06:13 +03:00
Merge pull request #3381 from n-thumann/fix_ipv6_handling
Fix handling of IPv6 addresses in getClientIP
This commit is contained in:
commit
2f5a565ce4
2 changed files with 12 additions and 2 deletions
|
@ -249,9 +249,9 @@ class UptimeKumaServer {
|
|||
|
||||
return (typeof forwardedFor === "string" ? forwardedFor.split(",")[0].trim() : null)
|
||||
|| socket.client.conn.request.headers["x-real-ip"]
|
||||
|| clientIP.replace(/^.*:/, "");
|
||||
|| clientIP.replace(/^::ffff:/, "");
|
||||
} else {
|
||||
return clientIP.replace(/^.*:/, "");
|
||||
return clientIP.replace(/^::ffff:/, "");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -306,6 +306,16 @@ describe("Test uptimeKumaServer.getClientIP()", () => {
|
|||
ip = await server.getClientIP(fakeSocket);
|
||||
expect(ip).toBe("203.0.113.195");
|
||||
|
||||
fakeSocket.client.conn.remoteAddress = "2001:db8::1";
|
||||
fakeSocket.client.conn.request.headers = {};
|
||||
ip = await server.getClientIP(fakeSocket);
|
||||
expect(ip).toBe("2001:db8::1");
|
||||
|
||||
fakeSocket.client.conn.remoteAddress = "::ffff:127.0.0.1";
|
||||
fakeSocket.client.conn.request.headers = {};
|
||||
ip = await server.getClientIP(fakeSocket);
|
||||
expect(ip).toBe("127.0.0.1");
|
||||
|
||||
await Database.close();
|
||||
}, 120000);
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue