Skip to content

Commit

Permalink
[IMP] hr_attendance_location_ip_check
Browse files Browse the repository at this point in the history
- Update get remote ip check to be more robust
  • Loading branch information
kongkea-aditi committed Dec 20, 2024
1 parent 0e002b3 commit d169ab7
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions hr_attendance_location_ip_check/models/hr_employee.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,16 @@ def _is_ip_allowed(self, ip_addr):
raise ValidationError(_("Invalid IP address format: %s") % ip_addr) from e

def _get_remote_ip(self):
"""Get remote IP from request."""
"""Get remote IP from request, considering proxy headers."""
try:
return request.httprequest.remote_addr if request else None
if request:
ip = request.httprequest.headers.get(
"X-Forwarded-For", request.httprequest.headers.get("X-Real-IP")
)
return (
ip.split(",")[0].strip() if ip else request.httprequest.remote_addr
)
return None
except Exception as e:
_logger.error("Error getting IP: %s", str(e))
return None
Expand Down

0 comments on commit d169ab7

Please sign in to comment.