From f6fbad84031ce3e907b689ff9aa3c79224a75053 Mon Sep 17 00:00:00 2001 From: thomas girod Date: Mon, 5 Aug 2024 15:53:41 +0200 Subject: [PATCH] fix missing HTTP_REFERER --- counter/utils.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/counter/utils.py b/counter/utils.py index 08ae0490..2b9b6fd6 100644 --- a/counter/utils.py +++ b/counter/utils.py @@ -23,13 +23,12 @@ def is_logged_in_counter(request: HttpRequest) -> bool: - The current session has a counter token associated with it. - A counter with this token exists. """ - referer = urlparse(request.META["HTTP_REFERER"]).path - path_ok = ( - request.resolver_match.app_name == "counter" - or resolve(referer).app_name == "counter" + referer_ok = ( + "HTTP_REFERER" in request.META + and resolve(urlparse(request.META["HTTP_REFERER"]).path).app_name == "counter" ) return ( - path_ok + (referer_ok or request.resolver_match.app_name == "counter") and "counter_token" in request.session and request.session["counter_token"] and Counter.objects.filter(token=request.session["counter_token"]).exists()