fix: conditionally set safe session monitoring (#29724)

Fixes a bug where a custom attribute was being set
even for cases where we did not have the appropriate
data, and an exception was being raised.

ARCHBOM-1940
This commit is contained in:
Robert Raposa
2022-01-06 16:49:58 -05:00
committed by GitHub
parent 973fb3c4c6
commit 8fa1d4d0b6

View File

@@ -505,8 +505,9 @@ class SafeSessionMiddleware(SessionMiddleware, MiddlewareMixin):
# add a session hash custom attribute for all requests to help monitoring
# requests that come both before and after a mistmatch
session_hash = obscure_token(request.cookie_session_field)
set_custom_attribute('safe_sessions.session_id_hash.parsed_cookie', session_hash)
if hasattr(request, 'cookie_session_field'):
session_hash = obscure_token(request.cookie_session_field)
set_custom_attribute('safe_sessions.session_id_hash.parsed_cookie', session_hash)
# log request header if this user id was involved in an earlier mismatch
log_request_headers = cache.get(