Skip to content

IPNetwork.Contains reports IPv4-mapped 0.x.x.x addresses as inside unrelated IPv6 networks #134557

Closed as duplicate

Description

@APKiwi

On .NET 10.0.12 (macOS arm64) IPNetwork.Contains returns true for IPv4-mapped addresses whose IPv4 part is in 0.0.0.0/8 when the network is an IPv6 range that does not contain them.

using System.Net;
Console.WriteLine(IPNetwork.Parse("fd00::/8").Contains(IPAddress.Parse("::ffff:0:0")));      // True, expected False
Console.WriteLine(IPNetwork.Parse("::1/128").Contains(IPAddress.Parse("::ffff:0.0.0.1")));   // True, expected False
Console.WriteLine(IPNetwork.Parse("fd00::/8").Contains(IPAddress.Parse("::ffff:10.0.0.1"))); // False, correct
Console.WriteLine(IPNetwork.Parse("fd00::/8").Contains(IPAddress.Parse("fe80::1")));         // False, correct

It looks limited to mapped addresses in 0.0.0.0/8. ForwardedHeadersMiddleware relies on Contains for its known network check, so a peer in that range can be matched against the wrong network. We worked around it by comparing prefix bits ourselves.

Activity

  1. added
    untriaged
    on Sep 23, 2026
  2. dotnet-policy-service commented on Sep 23, 2026

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @karelz, @dotnet/ncl
    See info in area-owners.md if you want to be subscribed.

  3. MihuBot commented on Sep 23, 2026

    @MihuBot

    I'm a bot. Here is a possible related and/or duplicate issue (I may be wrong):

  4. removed
    untriaged
    on Sep 24, 2026
  5. added this to the 12.0.0 milestone on Sep 24, 2026
  6. MihaZupan commented on Sep 24, 2026

    @MihaZupan
    Member

    The duplicate looks right, this was fixed for .NET 11 in #131862.

  7. locked and limited conversation to collaborators on Oct 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions