From 7ac744eac88c5f3b8d67ef28c6f495d1db3ab474 Mon Sep 17 00:00:00 2001 From: Johannes Laurin Hoermann Date: Wed, 20 Nov 2024 15:35:52 +0100 Subject: [PATCH 1/2] MAINT: more possible proxy field cases treated --- dserver_notification_plugin/__init__.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/dserver_notification_plugin/__init__.py b/dserver_notification_plugin/__init__.py index d287817..e16ca4d 100644 --- a/dserver_notification_plugin/__init__.py +++ b/dserver_notification_plugin/__init__.py @@ -80,7 +80,22 @@ def filter_ips(f): @wraps(f) def wrapped(*args, **kwargs): # Check if header has been rewritten by reverse proxy and look into HTTP_X_REAL_IP first - real_ip = request.headers.get('HTTP_X_REAL_IP', request.remote_addr) + + real_ip = request.headers.get('HTTP_X_REAL_IP', None) + + if real_ip is None: + logger.debug("request.headers does not contain field HTTP_X_REAL_IP, try X-Forwarded-For") + real_ip = request.headers.get('X-Forwarded-For', None) + + if real_ip is None: + logger.debug("request.headers does not contain field X-Forwarded-For, try X-Real-IP") + real_ip = request.headers.get('X-Real-IP', None) + + if real_ip is None: + logger.debug("request.headers does not contain field HTTP_X_REAL_IP.") + real_ip = request.remote_addr + logger.debug("Instead use request.remote_addr '%s%'.", real_ip) + ip = ipaddress.ip_address(real_ip) logger.info("Accessed from %s", ip) if ip in Config.ALLOW_ACCESS_FROM: From cfb029b9f711679a5711a134894a28fe72b3f5cd Mon Sep 17 00:00:00 2001 From: Johannes Laurin Hoermann Date: Wed, 20 Nov 2024 15:37:00 +0100 Subject: [PATCH 2/2] DOC: Changelog --- CHANGELOG.rst | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 4744a50..a06d337 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,7 +1,12 @@ Change log for dserver-notification-plugin ========================================== -0.4.2 (9Jul24) +0.4.3 (20Nov24) +--------------- + +* Detailed logging, more header fields treated. + +0.4.2 (20Nov24) --------------- * Return proper error code on request without content.