Skip to content

gh-117566: fix IPv6Address.is_loopback for IPv4-mapped loopbacks - #117567

Merged
encukou merged 2 commits into
python:mainfrom
paravoid:ipv4-mapped-loopback
Apr 25, 2024
Merged

encukou merged 2 commits into
python:mainfrom
paravoid:ipv4-mapped-loopback

Conversation

@paravoid

@paravoid paravoid commented Apr 5, 2024 •

Copy link
Copy Markdown
Contributor

While properties like IPv6Address.is_private account for IPv4-mapped IPv6 addresses, such as for example:

>>> ipaddress.ip_address("192.168.0.1").is_private
True
>>> ipaddress.ip_address("::ffff:192.168.0.1").is_private
True

...the same doesn't currently apply to the is_loopback property:

>>> ipaddress.ip_address("127.0.0.1").is_loopback
True
>>> ipaddress.ip_address("::ffff:127.0.0.1").is_loopback
False

At minimum, this inconsistency between different properties is counter-intuitive. Moreover, ::ffff:127.0.0.0/104 is for all intents and purposes a loopback address, and should be treated as such.

@ghost

ghost commented Apr 5, 2024 •

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.
CLA signed

@bedevere-app

bedevere-app Bot commented Apr 5, 2024

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@paravoid

Copy link
Copy Markdown
Contributor Author

@encukou @gpshead, I noticed that you've reviewed this area of code before, and hopefully this is going to be a trivial one for you :) (Apologies beforehand if the direct ping is undesired/spammy, not sure about the etiquette here!)

@encukou

encukou commented Apr 23, 2024

Copy link
Copy Markdown
Member

Thanks for the fix.
Could you add a simple test as well?

While properties like IPv6Address.is_private account for IPv4-mapped
IPv6 addresses, such as for example:

    >>> ipaddress.ip_address("192.168.0.1").is_private
    True
    >>> ipaddress.ip_address("::ffff:192.168.0.1").is_private
    True
...the same doesn't currently apply to the is_loopback property:
    >>> ipaddress.ip_address("127.0.0.1").is_loopback
    True
    >>> ipaddress.ip_address("::ffff:127.0.0.1").is_loopback
    False

At minimum, this inconsistency between different properties is
counter-intuitive. Moreover, ::ffff:127.0.0.0/104 is for all intents and
purposes a loopback address, and should be treated as such.
@paravoid
paravoid force-pushed the ipv4-mapped-loopback branch from e07c72b to 35c5efb Compare April 25, 2024 11:15
@paravoid

Copy link
Copy Markdown
Contributor Author

Thanks for the fix. Could you add a simple test as well?

Thanks for the quick review! That's a good point, I added tests now as well.

Comment thread Lib/test/test_ipaddress.py Resolved

@encukou encukou left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thank you!

@encukou
encukou enabled auto-merge (squash) April 25, 2024 14:46
@encukou encukou added needs backport to 3.12 only security fixes and removed needs backport to 3.12 only security fixes labels Apr 25, 2024
@encukou
encukou merged commit fb7f79b into python:main Apr 25, 2024
@paravoid
paravoid deleted the ipv4-mapped-loopback branch April 25, 2024 15:35
@paravoid

Copy link
Copy Markdown
Contributor Author

Looks good, thank you!

Thank you so much for the super quick turnaround! Is this something that should/could also make it to 3.12.x or does it sit outside of the stable bugfix policies?

@encukou encukou added the needs backport to 3.12 only security fixes label Apr 29, 2024
@miss-islington-app

Copy link
Copy Markdown

Thanks @paravoid for the PR, and @encukou for merging it 🌮🎉.. I'm working now to backport this PR to: 3.12.
🐍🍒⛏🤖 I'm not a witch! I'm not a witch!

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Apr 29, 2024
pythonGH-117567)

While properties like IPv6Address.is_private account for IPv4-mapped
IPv6 addresses, such as for example:

    >>> ipaddress.ip_address("192.168.0.1").is_private
    True
    >>> ipaddress.ip_address("::ffff:192.168.0.1").is_private
    True
...the same doesn't currently apply to the is_loopback property:
    >>> ipaddress.ip_address("127.0.0.1").is_loopback
    True
    >>> ipaddress.ip_address("::ffff:127.0.0.1").is_loopback
    False

At minimum, this inconsistency between different properties is
counter-intuitive. Moreover, ::ffff:127.0.0.0/104 is for all intents and
purposes a loopback address, and should be treated as such.
(cherry picked from commit fb7f79b)

Co-authored-by: Faidon Liambotis <paravoid@debian.org>
@bedevere-app

bedevere-app Bot commented Apr 29, 2024

Copy link
Copy Markdown

GH-118391 is a backport of this pull request to the 3.12 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.12 only security fixes label Apr 29, 2024
encukou pushed a commit that referenced this pull request Apr 29, 2024
…ks (GH-117567) (GH-118391)

gh-117566: fix IPv6Address.is_loopback for IPv4-mapped loopbacks (GH-117567)

While properties like IPv6Address.is_private account for IPv4-mapped
IPv6 addresses, such as for example:

    >>> ipaddress.ip_address("192.168.0.1").is_private
    True
    >>> ipaddress.ip_address("::ffff:192.168.0.1").is_private
    True
...the same doesn't currently apply to the is_loopback property:
    >>> ipaddress.ip_address("127.0.0.1").is_loopback
    True
    >>> ipaddress.ip_address("::ffff:127.0.0.1").is_loopback
    False

At minimum, this inconsistency between different properties is
counter-intuitive. Moreover, ::ffff:127.0.0.0/104 is for all intents and
purposes a loopback address, and should be treated as such.

(cherry picked from commit fb7f79b)

Co-authored-by: Faidon Liambotis <paravoid@debian.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants