Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I can no longer use iptools.IpRangeList for INTERNAL_IPS #1928

Closed
quinox opened this issue May 30, 2024 · 5 comments · Fixed by #1929
Closed

I can no longer use iptools.IpRangeList for INTERNAL_IPS #1928

quinox opened this issue May 30, 2024 · 5 comments · Fixed by #1929

Comments

@quinox
Copy link
Contributor

quinox commented May 30, 2024

Hello!

Long time happy user of DDT here.

With 782bdd9 I can no longer use iptools.IpRangeList with INTERNAL_IPS, it blows up when I want to whitelist a larger IP range such as IPv6. With smaller ranges such as 10.0.0.0/8 it won't blow up but it will delay every request significantly while DDT waits for IpRangeList to write out all the IP addresses.

INTERNAL_IPS = iptools.IpRangeList('127.0.0.1', '10/8', '::1', '1a:1a:1a:1a::/64')
Traceback (most recent call last):
  File "/mnt/drive/skeleton/virtual/lib/python3.10/site-packages/django/core/handlers/exception.py", line 55, in inner
    response = get_response(request)
  File "/mnt/drive/skeleton/virtual/lib/python3.10/site-packages/debug_toolbar/middleware.py", line 64, in __call__
    if not show_toolbar(request) or DebugToolbar.is_toolbar_request(request):
  File "/mnt/drive/skeleton/virtual/lib/python3.10/site-packages/debug_toolbar/middleware.py", line 23, in show_toolbar
    internal_ips = list(settings.INTERNAL_IPS)
OverflowError: cannot fit 'int' into an index-sized integer

For now I simplified my configuration to work around it. My requirements have changed a bit over the years and I can live with this simplified setup, but I just wanted to let you know in case this fallout was undesirable.

@tim-schilling
Copy link
Member

Thanks for letting us know! Would you be interested in creating a PR to resolve this?

@quinox
Copy link
Contributor Author

quinox commented May 30, 2024

I'm happy to.

The commit doesn't state why a list was preferable. Looking around I assume the cast in 782bdd9 was done because in 7d77a34 the .copy()+append() was added, which didn't work on certain not-a-list objects.

For the biggest compatibility and efficiency I'd say the copy()+append() should not be done either. The code should go back to request.META.get("REMOTE_ADDR") in settings.INTERNAL_IPS. An additional clause can be added to deal with the Docker IP check separately.

I'll make a PR later today.

@tim-schilling
Copy link
Member

The reason was that the suggested docker solution was to add the docker internal host IP address to INTERNAL_IPS which is defined as a list. @matthiask does the docker host need to be added to INTERNAL_IPS? If yes, @quinox you may be headed down the wrong direction.

@quinox
Copy link
Contributor Author

quinox commented May 30, 2024

The Docker IP is added to a local copy of the Django setting. This variable gets destroyed at the end of the function.

I made the PR: #1929. I'm happy to amend it in any way should you so desire.

@matthiask
Copy link
Member

I have commented on the pull request. The change makes sense to me. INTERNAL_IPS is used by Django for a limited list of things: https://docs.djangoproject.com/en/5.0/ref/settings/#internal-ips

The toolbar won't have a problem when e.g. the debug() context processor variables aren't in the context.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants