Skip to content

Commit 3a1f8c8

Browse files
authored
Use session expiration for all authentication cookies (#18269)
Closes #18180
1 parent 6a5c50e commit 3a1f8c8

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

tests/unit/test_sessions.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ def test_invalidated_deletes_save_non_secure(self, monkeypatch, pyramid_request)
563563
pyramid_request.session.should_save = pretend.call_recorder(lambda: True)
564564
response = pretend.stub(
565565
set_cookie=pretend.call_recorder(
566-
lambda cookie, data, max_age, httponly, secure, samesite: None
566+
lambda cookie, data, httponly=False, secure=True, samesite=b"none": None
567567
)
568568
)
569569
session_factory._process_response(pyramid_request, response)
@@ -589,7 +589,6 @@ def test_invalidated_deletes_save_non_secure(self, monkeypatch, pyramid_request)
589589
pretend.call(
590590
"session_id",
591591
"cookie data",
592-
max_age=12 * 60 * 60,
593592
httponly=True,
594593
secure=False,
595594
samesite=b"lax",

warehouse/sessions.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,10 +301,16 @@ def _process_response(self, request, response):
301301
)
302302

303303
# Send our session cookie to the client
304+
# NOTE: The lack of a max_age here. This sends the cookie with:
305+
# > Expires: Session
306+
# This will allow effectively allow the cookie to live indefinitely,
307+
# as long as the user has interacted with the session _before_ the
308+
# session key expieres in redis.
309+
# Once the session key has expired in redis, the session will be marked
310+
# as invalid and will not authenticate the account.
304311
response.set_cookie(
305312
self.cookie_name,
306313
self.signer.sign(request.session.sid.encode("utf8")),
307-
max_age=self.max_age,
308314
httponly=True,
309315
secure=request.scheme == "https",
310316
samesite=b"lax",

0 commit comments

Comments
 (0)