Skip to content

Commit

Permalink
fix construction of cookie using user supplied input #12808 (#13029)
Browse files Browse the repository at this point in the history
  • Loading branch information
KumarVivekPathak authored Feb 11, 2025
1 parent eb25f29 commit f1c785c
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions kolibri/core/auth/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1046,17 +1046,12 @@ def get_session_response(self, request):

if isinstance(user, AnonymousUser):
response = Response(session)
if not request.COOKIES.get("visitor_id"):
visitor_id = str(uuid4().hex)
response.set_cookie(
"visitor_id", visitor_id, expires=visitor_cookie_expiry
)
else:
response.set_cookie(
"visitor_id",
request.COOKIES.get("visitor_id"),
expires=visitor_cookie_expiry,
)
try:
visitor_id = request.COOKIES.get("visitor_id")
visitor_id = UUID(visitor_id, version=4).hex
except (ValueError, TypeError):
visitor_id = uuid4().hex
response.set_cookie("visitor_id", visitor_id, expires=visitor_cookie_expiry)
return response
# Set last activity on session to the current time to prevent session timeout
# Only do this for logged in users, as anonymous users cannot get logged out!
Expand Down

0 comments on commit f1c785c

Please sign in to comment.