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

invalid literal for int() with base 10: 'unknown' #53

Open
jplehmann opened this issue Jan 25, 2019 · 2 comments
Open

invalid literal for int() with base 10: 'unknown' #53

jplehmann opened this issue Jan 25, 2019 · 2 comments

Comments

@jplehmann
Copy link

Using Django 1.11 and django-iprestrict==1.7.0:

  File "/app/.heroku/python/lib/python2.7/site-packages/django/core/handlers/exception.py", line 41, in inner 
    response = get_response(request) 
  File "/app/.heroku/python/lib/python2.7/site-packages/django/core/handlers/base.py", line 244, in _legacy_get_response 
    response = middleware_method(request) 
  File "/app/.heroku/python/lib/python2.7/site-packages/newrelic/hooks/framework_django.py", line 220, in wrapper 
    return wrapped(*args, **kwargs) 
  File "/app/.heroku/python/lib/python2.7/site-packages/iprestrict/middleware.py", line 42, in process_request 
    if self.restrictor.is_restricted(url, client_ip): 
  File "/app/.heroku/python/lib/python2.7/site-packages/iprestrict/restrictor.py", line 16, in is_restricted 
    if rule.matches_url(url) and rule.matches_ip(ip): 
  File "/app/.heroku/python/lib/python2.7/site-packages/iprestrict/models.py", line 229, in matches_ip 
    match = typed_ip_group(self.ip_group).matches(ip) 
  File "/app/.heroku/python/lib/python2.7/site-packages/iprestrict/models.py", line 101, in matches 
    if ip in r: 
  File "/app/.heroku/python/lib/python2.7/site-packages/iprestrict/models.py", line 167, in __contains__ 
    ip_nr = ipu.to_number(ip) 
  File "/app/.heroku/python/lib/python2.7/site-packages/iprestrict/ip_utils.py", line 22, in to_number 
    return ipv6_to_number(ip) if is_ipv6(ip) else ipv4_to_number(ip) 
  File "/app/.heroku/python/lib/python2.7/site-packages/iprestrict/ip_utils.py", line 26, in ipv4_to_number 
    return _ip_to_number(ip) 
  File "/app/.heroku/python/lib/python2.7/site-packages/iprestrict/ip_utils.py", line 88, in _ip_to_number 
    parts = [int(p, base) for p in reversed(parts)] 
ValueError: invalid literal for int() with base 10: 'unknown' 
@jplehmann
Copy link
Author

Dug a little deeper and the input data causing this problem is from Heroku's router, which looks like:

fwd="unknown,XXX.XXX.XXX.XXX"

where X was a valid number.

While I do not know why Heroku does this, iprestrict still needs to validate the input before trying to parse it, so as not to crash.

@MariKiev
Copy link

I have the same issue. How it can be fixed?

sztamas added a commit to sztamas/django-iprestrict-redux that referenced this issue Aug 30, 2020
Fixes muccg/django-iprestrict#53
References:
 * muccg/djang-iprestrict#54
 * #1
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

No branches or pull requests

2 participants