From 81cdb013ade41487029d88336e356312f7bfcec8 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 5 Jun 2023 15:54:05 +0200 Subject: [PATCH] [Fixes #11147] Strip port from visitor_ip_address (#11148) (#11150) * strip port from visitor_ip_address * gix PEP (cherry picked from commit 6887596c9672b2e5b6575e6e40c07b37951f4b8e) Co-authored-by: Giovanni Allegri --- geonode/base/auth.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/geonode/base/auth.py b/geonode/base/auth.py index cfef16bd820..e56d03edb01 100644 --- a/geonode/base/auth.py +++ b/geonode/base/auth.py @@ -259,6 +259,8 @@ def visitor_ip_address(request): ip = x_forwarded_for.split(",")[0] else: ip = request.META.get("REMOTE_ADDR") + if ip: + ip = re.match(r"(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})", ip)[0] return ip