Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

exception when remote IP makes no sense #85

Closed
dholth opened this Issue · 6 comments

6 participants

Daniel Holth Éric Araujo Hadrien David Blaise Laflamme Daniel Werner Chris McDonough
Daniel Holth
  response = self.handle_request(request)
  File "pyramid_debugtoolbar/toolbar.py", line 108, in toolbar_tween
    if ipaddr.IPAddress(remote_addr) in ipaddr.IPNetwork(host):
  File "pyramid_debugtoolbar/ipaddr.py", line 85, in IPAddress
    address)
ValueError: '192.168.117.153, 216.53.134.86' does not appear to be an IPv4 or IPv6 address

pyramid-debugtoolbar==1.0.2

Éric Araujo

From a coworker: it looks like the IP is taken from HTTP_X_FORWARDED_FOR and parsed wrongly.

Hadrien David

Got it on 1.0.3:

Traceback (most recent call last):
  File "/opt/python-hayk/lib/python2.7/site-packages/PasteDeploy-1.5.0-py2.7.egg/paste/deploy/config.py", line 291, in __call__
    return self.app(environ, start_response)
  File "/opt/python-hayk/lib/python2.7/site-packages/pyramid-1.3.4-py2.7.egg/pyramid/router.py", line 187, in __call__
    response = self.handle_request(request)
  File "/opt/python-hayk/lib/python2.7/site-packages/pyramid_debugtoolbar-1.0.3-py2.7.egg/pyramid_debugtoolbar/toolbar.py", line 105, in toolbar_tween
    or (not addr_in(remote_addr, hosts)) ):
  File "/opt/python-hayk/lib/python2.7/site-packages/pyramid_debugtoolbar-1.0.3-py2.7.egg/pyramid_debugtoolbar/utils.py", line 158, in addr_in
    if ipaddr.IPAddress(addr) in ipaddr.IPNetwork(host):
  File "/opt/python-hayk/lib/python2.7/site-packages/pyramid_debugtoolbar-1.0.3-py2.7.egg/pyramid_debugtoolbar/ipaddr.py", line 85, in IPAddress
    address)
ValueError: '172.16.63.156, 64.119.211.105' does not appear to be an IPv4 or IPv6 address
Hadrien David

reproduced by:

from pyramid import testing
from pyramid.response import Response
from pyramid.request import Request
from pyramid_debugtoolbar.toolbar import toolbar_tween_factory

config = testing.setUp()

config.add_route('debugtoolbar.root', '/_debug_toolbar')
config.add_static_view('_debugtoolbar/static', '/')

settings = config.registry.settings
settings['debugtoolbar.enabled'] = True
settings['debugtoolbar.hosts'] = ['127.0.0.1']
settings['mako.directories'] = []
settings['debugtoolbar.exclude_prefixes'] = ['/excluded']

registry = config.registry

request = Request.blank('/')

# behind proxies:
request.remote_addr = '172.16.63.156, 64.119.211.105'

def handler(request):
    return Response('OK')
handler = toolbar_tween_factory(handler, registry)

# this call will fail
handler(request)

Will give:

Traceback (most recent call last):
  File "reproduce.py", line 27, in <module>
    handler(request)
  File ".virtualenvs/mp34/lib/python2.7/site-packages/pyramid_debugtoolbar-1.0.4-py2.7.egg/pyramid_debugtoolbar/toolbar.py", line 109, in toolbar_tween
    (not addr_in(remote_addr, hosts))
  File ".virtualenvs/mp34/lib/python2.7/site-packages/pyramid_debugtoolbar-1.0.4-py2.7.egg/pyramid_debugtoolbar/utils.py", line 158, in addr_in
    if ipaddr.IPAddress(addr) in ipaddr.IPNetwork(host):
  File ".virtualenvs/mp34/lib/python2.7/site-packages/pyramid_debugtoolbar-1.0.4-py2.7.egg/pyramid_debugtoolbar/ipaddr.py", line 85, in IPAddress
    address)
ValueError: '172.16.63.156, 64.119.211.105' does not appear to be an IPv4 or IPv6 address
Hadrien David hadrien referenced this issue from a commit in hadrien/pyramid_debugtoolbar
Hadrien David hadrien Fixed bug #85 when request.remote_addr is a comma separated list of p…
…roxies IPs
c9abe1c
Éric Araujo

Hi Blaise, thanks for merging this. Could you tell us when this fix will be part of a release?

Blaise Laflamme
Owner

Let me see if there are other pull requests to merge and do a release

Daniel Werner

I still receive a similar exception with a pyramid application that runs behind an nginx proxy:

Module weberror.errormiddleware:162 in __call__
>>  app_iter = self.application(environ, sr_checker)
Module pyramid.router:187 in __call__
>>  response = self.handle_request(request)
Module pyramid_debugtoolbar.toolbar:130 in toolbar_tween
>>  return handler(request)
Module pyramid.tweens:20 in excview_tween
>>  response = handler(request)
Module pyramid_tm:95 in tm_tween
>>  response = handler(request)
Module pyramid.router:164 in handle_request
>>  response = view_callable(context, request)
Module pyramid.config.views:307 in attr_view
>>  return view(context, request)
Module pyramid.config.views:279 in predicate_wrapper
>>  if all((predicate(context, request) for predicate in predicates)):
Module pyramid.config.views:279 in <genexpr>
>>  if all((predicate(context, request) for predicate in predicates)):
Module pyramid_debugtoolbar.views:26 in valid_host
>>  return addr_in(request.remote_addr, hosts)
Module pyramid_debugtoolbar.utils:158 in addr_in
>>  if ipaddr.IPAddress(addr) in ipaddr.IPNetwork(host):
Module pyramid_debugtoolbar.ipaddr:85 in IPAddress
>>  address)
ValueError: '188.174.236.210, 192.168.0.1' does not appear to be an IPv4 or IPv6 address

I'm running pyramid_debugtoolbar==1.0.6. It seems the issue has been fixed for one area of the code, but this time the exception happens in another part.

Daniel Werner danwerner referenced this issue from a commit in gulp-swe/pyramid_debugtoolbar
Daniel Werner danwerner Fixed another case impacted by bug #85 f32898d
Chris McDonough mcdonc closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.