1
0
mirror of https://github.com/bitwarden/server.git synced 2024-11-22 12:15:36 +01:00

update ip IsInternal() to account for missed ranges (#827)

* update ip IsInternal() to account for missed ranges

* update with `::`
This commit is contained in:
Kyle Spearrin 2020-07-18 08:08:57 -04:00 committed by GitHub
parent 3b9f625bc1
commit 036b402e9f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -419,15 +419,28 @@ namespace Bit.Icons.Services
{
return true;
}
else if (ip.ToString() == "::1")
var ipString = ip.ToString();
if (ipString == "::1" || ipString == "::")
{
return false;
return true;
}
// IPv6
if (ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetworkV6)
{
return ipString.StartsWith("fc") || ipString.StartsWith("fd") ||
ipString.StartsWith("fe") || ipString.StartsWith("ff");
}
// IPv4
var bytes = ip.GetAddressBytes();
return (bytes[0]) switch
{
0 => true,
10 => true,
127 => true,
169 => bytes[1] == 254, // Cloud environments, such as AWS
172 => bytes[1] < 32 && bytes[1] >= 16,
192 => bytes[1] == 168,
_ => false,