Title: ipaddress considers some not globally reachable addresses global and vice versa · Issue #113171 · python/cpython · GitHub
Open Graph Title: ipaddress considers some not globally reachable addresses global and vice versa · Issue #113171 · python/cpython
X Title: ipaddress considers some not globally reachable addresses global and vice versa · Issue #113171 · python/cpython
Description: Bug report Bug description: Judging by what the is_private and is_global implementations in the ipaddress module do[1], everything that IANA special-purpose address registries[2][3] considers globally reachable should result in is_global...
Open Graph Description: Bug report Bug description: Judging by what the is_private and is_global implementations in the ipaddress module do[1], everything that IANA special-purpose address registries[2][3] considers globa...
X Description: Bug report Bug description: Judging by what the is_private and is_global implementations in the ipaddress module do[1], everything that IANA special-purpose address registries[2][3] considers globa...
Opengraph URL: https://github.com/python/cpython/issues/113171
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"ipaddress considers some not globally reachable addresses global and vice versa","articleBody":"# Bug report\r\n\r\n### Bug description:\r\n\r\nJudging by what the `is_private` and `is_global` implementations in the `ipaddress` module do[1], everything that IANA special-purpose address registries[2][3] considers globally reachable should result in `is_global == True`, the rest should be `is_global = True`. \r\n\r\n`is_private` is almost always the opposite of `is_global` (`100.64.0.0/10` is special).\r\n\r\nThe problem is the ranges present in the code (in the `_private_networks` variables) are not quite right:\r\n\r\n* There are some ranges missing (so we incorrectly treat them as globally reachable)\r\n* Some of the ranges fail to account for more specific allocations defined as globally reachable (so we incorrectly treat them as not globally reachable)\r\n\r\nThis is what I have right now and I'll submit that as a PR:\r\n\r\n```diff\r\ndiff --git a/Lib/ipaddress.py b/Lib/ipaddress.py\r\nindex 5b5520b92bde..3ee565bcd30b 100644\r\n--- a/Lib/ipaddress.py\r\n+++ b/Lib/ipaddress.py\r\n@@ -1558,13 +1558,18 @@ class _IPv4Constants:\r\n \r\n _public_network = IPv4Network('100.64.0.0/10')\r\n \r\n+ # Not globally reachable address blocks listed on\r\n+ # https://www.iana.org/assignments/iana-ipv4-special-registry/iana-ipv4-special-registry.xhtml\r\n _private_networks = [\r\n IPv4Network('0.0.0.0/8'),\r\n IPv4Network('10.0.0.0/8'),\r\n+ # 100.64.0.0/10 missing\r\n IPv4Network('127.0.0.0/8'),\r\n IPv4Network('169.254.0.0/16'),\r\n IPv4Network('172.16.0.0/12'),\r\n+ # Incomplete. Should be 192.0.0.0/24 - (192.0.0.9/32 + 192.0.0.10/32)\r\n IPv4Network('192.0.0.0/29'),\r\n+ # 192.0.0.8/32 missing\r\n IPv4Network('192.0.0.170/31'),\r\n IPv4Network('192.0.2.0/24'),\r\n IPv4Network('192.168.0.0/16'),\r\n@@ -2306,15 +2311,31 @@ class _IPv6Constants:\r\n \r\n _multicast_network = IPv6Network('ff00::/8')\r\n \r\n+ # Not globally reachable address blocks listed on\r\n+ # https://www.iana.org/assignments/iana-ipv6-special-registry/iana-ipv6-special-registry.xhtml\r\n _private_networks = [\r\n IPv6Network('::1/128'),\r\n IPv6Network('::/128'),\r\n IPv6Network('::ffff:0:0/96'),\r\n+ # 64:ff9b:1::/48 missing\r\n IPv6Network('100::/64'),\r\n+ # Not quite right as there are multiple more specific allocations that are globally\r\n+ # reachable. Should be:\r\n+ # 2001::/23 - (\r\n+ # 2001:1::1/128\r\n+ # + 2001:1::2/128\r\n+ # + 2001:3::/32\r\n+ # + 2001:4:112::/48\r\n+ # + 2001:20::/28\r\n+ # + 2001:30::/28\r\n+ # )\r\n IPv6Network('2001::/23'),\r\n+ # Unnecessary, covered by 2001::/23\r\n IPv6Network('2001:2::/48'),\r\n IPv6Network('2001:db8::/32'),\r\n+ # Unnecessary, covered by 2001::/23\r\n IPv6Network('2001:10::/28'),\r\n+ # Potentially 2002::/16 missing? IANA says N/A, there is no true/false value\r\n IPv6Network('fc00::/7'),\r\n IPv6Network('fe80::/10'),\r\n ]\r\n```\r\n\r\n[1] And which should really be documented per #65056 – a separate issue though\r\n[2] https://www.iana.org/assignments/iana-ipv4-special-registry/iana-ipv4-special-registry.xhtml\r\n[3] https://www.iana.org/assignments/iana-ipv6-special-registry/iana-ipv6-special-registry.xhtml\r\n\r\n### CPython versions tested on:\r\n\r\nCPython main branch\r\n\r\n### Operating systems tested on:\r\n\r\n_No response_\r\n\r\n\u003c!-- gh-linked-prs --\u003e\r\n### Linked PRs\r\n* gh-113179\r\n* gh-118177\n* gh-118227\n* gh-118229\n* gh-118472\n* gh-118479\n\u003c!-- /gh-linked-prs --\u003e\r\n","author":{"url":"https://github.com/jstasiak","@type":"Person","name":"jstasiak"},"datePublished":"2023-12-15T13:58:56.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":9},"url":"https://github.com/113171/cpython/issues/113171"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:bdbb39e8-5cc4-8963-bdb3-ef0abdeaaaa5 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | CE04:1025CE:4BD81F:65FCCC:6969B0BC |
| html-safe-nonce | 2b298c565ebb5502d8aa11bfd8a1628e4a5bf62c4596f6eb9259147a14f3a8fb |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDRTA0OjEwMjVDRTo0QkQ4MUY6NjVGQ0NDOjY5NjlCMEJDIiwidmlzaXRvcl9pZCI6IjQ0ODYwMDU0NTg4MTk3MjM0NTIiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | d883f1ae515be787acb57cd86c74051727e4b1f4e9549cf88a5c879d5af29dc9 |
| hovercard-subject-tag | issue:2043777514 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/113171/issue_layout |
| twitter:image | https://opengraph.githubassets.com/2720f01c19477d24e5eecb51280cd1ba0afbc8cedc071337ee20f4669b0612da/python/cpython/issues/113171 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/2720f01c19477d24e5eecb51280cd1ba0afbc8cedc071337ee20f4669b0612da/python/cpython/issues/113171 |
| og:image:alt | Bug report Bug description: Judging by what the is_private and is_global implementations in the ipaddress module do[1], everything that IANA special-purpose address registries[2][3] considers globa... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | jstasiak |
| hostname | github.com |
| expected-hostname | github.com |
| None | b23b8fcc855cd29bb04d6c94aafa62d336bf44eefa8229444eecc968cad03aee |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 0672399d88424758731ec07fe24509e23bb17fb5 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width