From b95f0c64f774306b917c73657a023cdbc5e9831e Mon Sep 17 00:00:00 2001 From: altaf-creator Date: Wed, 3 Dec 2025 19:02:46 +0700 Subject: cookie max age --- backend/main.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'backend/main.py') diff --git a/backend/main.py b/backend/main.py index e7cbd84..aaab7a1 100644 --- a/backend/main.py +++ b/backend/main.py @@ -224,20 +224,24 @@ def final_timer_finished(timer_id): machine_status[row[RowIndices.BLOCK] - 1][row[RowIndices.MACHINE] - 1] = Status.FINISHED.name +# sec min hrs days +COOKIE_MAX_AGE = 60 * 60 * 24 * 30 # 30 days + + def create_session(response: fastapi.Response): cookie = secrets.token_hex(32) - response.set_cookie(key="session_key", value=cookie, secure=True) + response.set_cookie(key="session_key", value=cookie, secure=True, max_age=COOKIE_MAX_AGE) return cookie def authenticate_block(response: fastapi.Response, machine_id: str = None, block: int = None): if machine_id: blk = URI_TO_MACHINES[qr_uri[machine_id]][0] - response.set_cookie(key="auth_block", value=blk, secure=True) + response.set_cookie(key="auth_block", value=blk, secure=True, max_age=COOKIE_MAX_AGE) return blk elif block: blk = block - response.set_cookie(key="auth_block", value=blk, secure=True) + response.set_cookie(key="auth_block", value=blk, secure=True, max_age=COOKIE_MAX_AGE) return block else: return "FAIL" -- cgit v1.2.3