Skip to content

Commit bf8ee40

Browse files
authored
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.
1 parent 296b5ed commit bf8ee40

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

rest_framework_sso/models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ def __str__(self):
5252

5353
def update_attributes(self, request):
5454
if request.META.get("HTTP_X_FORWARDED_FOR"):
55-
self.ip_address = request.META.get("HTTP_X_FORWARDED_FOR")
55+
self.ip_address = request.META.get("HTTP_X_FORWARDED_FOR").split(",")[0].strip()
5656
elif request.META.get("REMOTE_ADDR"):
57-
self.ip_address = request.META.get("REMOTE_ADDR")
57+
self.ip_address = request.META.get("REMOTE_ADDR").split(",")[0].strip()
5858
else:
5959
self.ip_address = None
6060

0 commit comments

Comments
 (0)