Closed
Description
Describe the bug
In AspNetCore/src/Middleware/HttpOverrides/src/IPNetwork.cs
The code below assumes that the prefix will have all bits in position > mask length set to 0. I do not believe that this a requirement for CIDR notation. If it is, it is not applied consistently since the routine will break if the mask is == 0 at a given byte.
for (int i = 0; i < PrefixBytes.Length && Mask[i] != 0; i++)
{
if (PrefixBytes[i] != (addressBytes[i] & Mask[i]))
{
return false;
}
}
To Reproduce
Create instance with Prefix/Prefix Length 192.168.0.1/31.
Contains returns false for 192.168.0.0.
Expected behavior
Expectation is that 192.168.0.1/31 would match 192.168.0.0