Skip to content

Commit

Permalink
Merge pull request #21 from livMatS/2024-11-20-fix-ip-filter-extended
Browse files Browse the repository at this point in the history
2024 11 20 fix ip filter extended
  • Loading branch information
jotelha authored Nov 20, 2024
2 parents 7904642 + cfb029b commit bc2d32f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
17 changes: 16 additions & 1 deletion dserver_notification_plugin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit bc2d32f

Please sign in to comment.