From 4224fd5c6fec8aa8d606f49692503b18b7917df7 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Sun, 12 Dec 2021 20:54:29 +0100 Subject: [PATCH] lib: correctly report "faked" IPs to sentry Signed-off-by: Jens Langhammer --- authentik/lib/utils/http.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/authentik/lib/utils/http.py b/authentik/lib/utils/http.py index deb1a2ffb..a6ea7cfab 100644 --- a/authentik/lib/utils/http.py +++ b/authentik/lib/utils/http.py @@ -4,6 +4,7 @@ from typing import Any, Optional from django.http import HttpRequest from requests.sessions import Session +from sentry_sdk.hub import Hub from structlog.stdlib import get_logger from authentik import ENV_GIT_HASH_KEY, __version__ @@ -52,6 +53,12 @@ def _get_outpost_override_ip(request: HttpRequest) -> Optional[str]: fake_ip=fake_ip, ) return None + # Update sentry scope to include correct IP + user = Hub.current.scope._user + if not user: + user = {} + user["ip_address"] = fake_ip + Hub.current.scope.set_user(user) return fake_ip