dev: admin session cookie update

This commit is contained in:
pablohashescobar 2024-05-03 17:46:28 +05:30
parent 77e38b6124
commit e8567b521c
2 changed files with 11 additions and 3 deletions

View File

@ -38,11 +38,13 @@ class SessionMiddleware(MiddlewareMixin):
return response return response
# First check if we need to delete this cookie. # First check if we need to delete this cookie.
# The session should be deleted only if the session is entirely empty. # The session should be deleted only if the session is entirely empty.
is_admin_path = "instances" in request.path
cookie_name = ( cookie_name = (
settings.ADMIN_SESSION_COOKIE_NAME settings.ADMIN_SESSION_COOKIE_NAME
if "instances" in request.path if is_admin_path
else settings.SESSION_COOKIE_NAME else settings.SESSION_COOKIE_NAME
) )
if cookie_name in request.COOKIES and empty: if cookie_name in request.COOKIES and empty:
response.delete_cookie( response.delete_cookie(
cookie_name, cookie_name,
@ -59,11 +61,16 @@ class SessionMiddleware(MiddlewareMixin):
max_age = None max_age = None
expires = None expires = None
else: else:
max_age = request.session.get_expiry_age() # Use different max_age based on whether it's an admin cookie
if is_admin_path:
max_age = settings.ADMIN_SESSION_COOKIE_AGE
else:
max_age = request.session.get_expiry_age()
expires_time = time.time() + max_age expires_time = time.time() + max_age
expires = http_date(expires_time) expires = http_date(expires_time)
# Save the session data and refresh the client cookie. # Save the session data and refresh the client cookie.
# Skip session save for 5xx responses.
if response.status_code < 500: if response.status_code < 500:
try: try:
request.session.save() request.session.save()

View File

@ -333,6 +333,7 @@ SESSION_SAVE_EVERY_REQUEST = True
# Admin Cookie # Admin Cookie
ADMIN_SESSION_COOKIE_NAME = "plane-admin-session-id" ADMIN_SESSION_COOKIE_NAME = "plane-admin-session-id"
ADMIN_SESSION_COOKIE_AGE = 18000
# CSRF cookies # CSRF cookies
CSRF_COOKIE_SECURE = secure_origins CSRF_COOKIE_SECURE = secure_origins