diff --git a/authentication/models.py b/authentication/models.py index c621ae20fe..e49ab0679e 100644 --- a/authentication/models.py +++ b/authentication/models.py @@ -5,7 +5,7 @@ from django.core.exceptions import ValidationError from django.db import models from django.utils.safestring import mark_safe -from ipware.utils import is_private_ip +from python_ipware import IpWare from main.models import TimestampedModel @@ -40,11 +40,13 @@ class BlockedIPRange(TimestampedModel): ip_end = models.GenericIPAddressField(null=False, blank=False) def clean(self): + ipw = IpWare() for ip in (self.ip_start, self.ip_end): if ip is None: msg = "IP cannot be null" raise ValidationError(msg, code="invalid") - if is_private_ip(ip): + ipw_ip = ipw.parse_ip_address(ip) + if ipw_ip.is_private: msg = f"IP {ip} is not routable" raise ValidationError(msg, code="invalid") if ip_address(self.ip_start) > ip_address(self.ip_end): diff --git a/poetry.lock b/poetry.lock index 5f5627ab9e..9917762d84 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1034,15 +1034,18 @@ async-rq = ["django-rq (>=0.6.0)"] [[package]] name = "django-ipware" -version = "3.0.7" +version = "7.0.1" description = "A Django application to retrieve user's IP address" optional = false -python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, !=3.5.*" +python-versions = ">=3.8" files = [ - {file = "django-ipware-3.0.7.tar.gz", hash = "sha256:753f8214a16ccaac54ea977349a96e37b582a28a54065e00c1c46d530862c85e"}, - {file = "django_ipware-3.0.7-py2.py3-none-any.whl", hash = "sha256:a18820ea2b98ff3f87b7530eb6346f5feb65d18e89397606aacc098fa7b93db2"}, + {file = "django-ipware-7.0.1.tar.gz", hash = "sha256:d9ec43d2bf7cdf216fed8d494a084deb5761a54860a53b2e74346a4f384cff47"}, + {file = "django_ipware-7.0.1-py2.py3-none-any.whl", hash = "sha256:db16bbee920f661ae7f678e4270460c85850f03c6761a4eaeb489bdc91f64709"}, ] +[package.dependencies] +python-ipware = ">=2.0.3" + [[package]] name = "django-json-widget" version = "1.1.1" @@ -2796,6 +2799,20 @@ files = [ [package.dependencies] six = ">=1.5" +[[package]] +name = "python-ipware" +version = "3.0.0" +description = "A Python package to retrieve user's IP address" +optional = false +python-versions = ">=3.7" +files = [ + {file = "python_ipware-3.0.0-py3-none-any.whl", hash = "sha256:fc936e6e7ec9fcc107f9315df40658f468ac72f739482a707181742882e36b60"}, + {file = "python_ipware-3.0.0.tar.gz", hash = "sha256:9117b1c4dddcb5d5ca49e6a9617de2fc66aec2ef35394563ac4eecabdf58c062"}, +] + +[package.extras] +dev = ["coverage[toml]", "coveralls (>=3.3,<4.0)", "ruff", "twine"] + [[package]] name = "python-rapidjson" version = "1.16" @@ -3951,4 +3968,4 @@ testing = ["big-O", "jaraco.functools", "jaraco.itertools", "more-itertools", "p [metadata] lock-version = "2.0" python-versions = "3.12.3" -content-hash = "c0a0acc76f21e06cba9b98fc5c79b3724355fe0721831bf47688ac14510d7f9d" +content-hash = "312ec8cc6ef9e720c7e567a3e0c383d5ecef0f92ea508c15b9edb817359ea10d" diff --git a/pyproject.toml b/pyproject.toml index cdc9edbd2f..1bf4791d85 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -29,7 +29,7 @@ django-filter = "^2.4.0" django-guardian = "^2.4.0" django-hijack = "^3.4.1" django-imagekit = "^5.0.0" -django-ipware = "^3.0.7" +django-ipware = "^7.0.0" django-json-widget = "^1.0.0" django-redis = "^5.2.0" django-server-status = "^0.7.0"