flask-ipban icon indicating copy to clipboard operation
flask-ipban copied to clipboard

Random ValueError for invalid IP address

Open jrecasens opened this issue 2 years ago • 1 comments

While running my app in Azure Web Apps I get the following random message:

2023-02-01T14:43:52.351399543Z 2023-02-01 09:43:52,332 - main - ERROR - Exception on /favicon.png [GET]
2023-02-01T14:43:52.351437144Z Traceback (most recent call last):
2023-02-01T14:43:52.351444244Z   File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 2077, in wsgi_app
2023-02-01T14:43:52.351449044Z     response = self.full_dispatch_request()
2023-02-01T14:43:52.351453344Z   File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1526, in full_dispatch_request
2023-02-01T14:43:52.351458044Z     return self.finalize_request(rv)
2023-02-01T14:43:52.351462144Z   File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1547, in finalize_request
2023-02-01T14:43:52.351466744Z     response = self.process_response(response)
2023-02-01T14:43:52.351470744Z   File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1889, in process_response
2023-02-01T14:43:52.351475044Z     response = self.ensure_sync(func)(response)
2023-02-01T14:43:52.351479244Z   File "/usr/local/lib/python3.9/site-packages/flask_ipban/ip_ban.py", line 116, in _after_request
2023-02-01T14:43:52.351483544Z     self.add()
2023-02-01T14:43:52.351487544Z   File "/usr/local/lib/python3.9/site-packages/flask_ipban/ip_ban.py", line 378, in add
2023-02-01T14:43:52.351501344Z     if self.test_pattern_blocklist(url, ip=ip):
2023-02-01T14:43:52.351525244Z   File "/usr/local/lib/python3.9/site-packages/flask_ipban/ip_ban.py", line 194, in test_pattern_blocklist
2023-02-01T14:43:52.351529244Z     ip_address = ipaddress.ip_address(ip)
2023-02-01T14:43:52.351550845Z   File "/usr/local/lib/python3.9/ipaddress.py", line 53, in ip_address
2023-02-01T14:43:52.351555245Z     raise ValueError(f'{address!r} does not appear to be an IPv4 or IPv6 address')
2023-02-01T14:43:52.351559245Z ValueError: '37.72.178.237:44837' does not appear to be an IPv4 or IPv6 address

My app is located in east-us server and looks like this problematic IP is from Russia:

37.72.178.237:44837

I wonder why I get the message "does not appear to be an IPv4 or IPv6 address"

jrecasens avatar Feb 01 '23 17:02 jrecasens

That's not an ip number. That is an ip number port. I'm not sure why it is appearing here. How are you passing the real IP to IPBAN from your proxy ?

Martlark avatar Feb 03 '23 01:02 Martlark