IPNetwork.Contains uses the queried address to choose between IPv4 and IPv6 comparison logic. When an IPv4-mapped IPv6 address is queried against an IPv6 network, it can incorrectly use the IPv4 comparison path.
Expected behavior:
IPv4 networks continue to accept equivalent IPv4-mapped addresses.
IPv6 networks use IPv6 prefix semantics for all IPv6 addresses, including IPv4-mapped addresses.
Example:
IPNetwork network = IPNetwork.Parse("2a00::/13");
IPAddress address = IPAddress.Parse("::ffff:42.42.42.42");
Console.WriteLine(network.Contains(address));
The comparison path should be selected from the network’s address family rather than solely from the queried address.
IPNetwork.Containsuses the queried address to choose between IPv4 and IPv6 comparison logic. When an IPv4-mapped IPv6 address is queried against an IPv6 network, it can incorrectly use the IPv4 comparison path.Expected behavior:
IPv4 networks continue to accept equivalent IPv4-mapped addresses.
IPv6 networks use IPv6 prefix semantics for all IPv6 addresses, including IPv4-mapped addresses.
Example:
The comparison path should be selected from the network’s address family rather than solely from the queried address.