mirror of
https://github.com/bitwarden/server.git
synced 2025-04-08 14:38:15 -05:00
Resolve host to check for private IP address (#812)
This commit is contained in:
parent
7af50172e0
commit
8a46fcd301
@ -291,6 +291,13 @@ namespace Bit.Icons.Services
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Resolve host to make sure it is not an internal/private IP address
|
||||||
|
var hostEntry = Dns.GetHostEntry(uri.Host);
|
||||||
|
if (hostEntry?.AddressList.Any(ip => IsInternal(ip)) ?? true)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
using (var message = new HttpRequestMessage())
|
using (var message = new HttpRequestMessage())
|
||||||
{
|
{
|
||||||
message.RequestUri = uri;
|
message.RequestUri = uri;
|
||||||
@ -405,5 +412,26 @@ namespace Bit.Icons.Services
|
|||||||
{
|
{
|
||||||
return uri != null && uri.Scheme == "http" ? "http" : "https";
|
return uri != null && uri.Scheme == "http" ? "http" : "https";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static bool IsInternal(IPAddress ip)
|
||||||
|
{
|
||||||
|
if (IPAddress.IsLoopback(ip))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if (ip.ToString() == "::1")
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
var bytes = ip.GetAddressBytes();
|
||||||
|
return (bytes[0]) switch
|
||||||
|
{
|
||||||
|
10 => true,
|
||||||
|
172 => bytes[1] < 32 && bytes[1] >= 16,
|
||||||
|
192 => bytes[1] == 168,
|
||||||
|
_ => false,
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user