Coder Social home page Coder Social logo

Comments (5)

Tratcher avatar Tratcher commented on June 30, 2024

One trouble with this is that people have been adding the IPv6 versions as a workaround. Changing it internally will break them unless you also change the KnownNetworks values for them.

from basicmiddleware.

SebastianC avatar SebastianC commented on June 30, 2024

I had originally considered updating another property to ForwardedHeadersOptions to indicate that this conversion should be turned "on", and default it to "off". Would that resolve your concern?

If it's a KnownProxy, I can see how adding the mapped-value would work, but i was unable to create a KnownNetwork that would be matched appropriately.

from basicmiddleware.

SebastianC avatar SebastianC commented on June 30, 2024

My apologies for the spam, but another option would be to check both variations:

        private bool CheckKnownAddress(IPAddress address)
        {
            if (address.IsIPv4MappedToIPv6)
            {
                var ipv4Address = address.MapToIPv4();
                if (_options.KnownProxies.Contains(ipv4Address))
                {
                    return true;
                }
                foreach (var network in _options.KnownNetworks)
                {
                    if (network.Contains(ipv4Address))
                    {
                        return true;
                    }
                }
            }
            if (_options.KnownProxies.Contains(address))
            {
                return true;
            }
            foreach (var network in _options.KnownNetworks)
            {
                if (network.Contains(address))
                {
                    return true;
                }
            }
            return false;
        }

from basicmiddleware.

Tratcher avatar Tratcher commented on June 30, 2024

Checking both varians is a good mitigation.

How's this for a simplification?

        private bool CheckKnownAddress(IPAddress address)
        {
            if (address.IsIPv4MappedToIPv6)
            {
                var ipv4Address = address.MapToIPv4();
                if (CheckKnownAddress(ipv4Address))
                {
                   return true;
                }
            }

            if (_options.KnownProxies.Contains(address))
            {
                return true;
            }

            foreach (var network in _options.KnownNetworks)
            {
                if (network.Contains(address))
                {
                    return true;
                }
            }
            return false;
        }

from basicmiddleware.

SebastianC avatar SebastianC commented on June 30, 2024

Better than mine. Will update the PR.

from basicmiddleware.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.