From bf8ee400f811cd2ccc6e0d3672d8e5f8475a333c Mon Sep 17 00:00:00 2001 From: Andrei Avram Date: Tue, 23 Jul 2019 19:51:50 +0300 Subject: [PATCH] Support for multiple IPs in META field HTTP_X_FORWARDED_FOR and REMOTE_ADDR can have more than one IP in them (it can be a comma separated list, usually appended by some proxies from the client to the server) - if that is the case, then the saving of the model breaks with; `DataError: invalid input syntax for type inet: "213.x.x.x, 10.0.0.x"` (IPs redacted) in `views.py` when you save the token. --- rest_framework_sso/models.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rest_framework_sso/models.py b/rest_framework_sso/models.py index e1612b2..ef644c7 100644 --- a/rest_framework_sso/models.py +++ b/rest_framework_sso/models.py @@ -52,9 +52,9 @@ def __str__(self): def update_attributes(self, request): if request.META.get("HTTP_X_FORWARDED_FOR"): - self.ip_address = request.META.get("HTTP_X_FORWARDED_FOR") + self.ip_address = request.META.get("HTTP_X_FORWARDED_FOR").split(",")[0].strip() elif request.META.get("REMOTE_ADDR"): - self.ip_address = request.META.get("REMOTE_ADDR") + self.ip_address = request.META.get("REMOTE_ADDR").split(",")[0].strip() else: self.ip_address = None