-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: delete session metadata cookie (#126)
- Loading branch information
Showing
5 changed files
with
45 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
""" | ||
© Ocado Group | ||
Created on 23/07/2024 at 14:28:21(+01:00). | ||
""" | ||
|
||
from .session import SessionMiddleware |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
""" | ||
© Ocado Group | ||
Created on 23/07/2024 at 14:18:28(+01:00). | ||
""" | ||
|
||
from django.conf import settings | ||
from django.contrib.sessions.middleware import ( | ||
SessionMiddleware as _SessionMiddleware, | ||
) | ||
|
||
|
||
class SessionMiddleware(_SessionMiddleware): | ||
""" | ||
Override the session middleware to delete the session metadata cookie when | ||
the session key cookie is deleted. | ||
""" | ||
|
||
def process_response(self, request, response): | ||
response = super().process_response(request, response) | ||
|
||
session = response.cookies.get(settings.SESSION_COOKIE_NAME) | ||
if ( | ||
session | ||
and session.get("max-age") == 0 | ||
and session.get("expires") == "Thu, 01 Jan 1970 00:00:00 GMT" | ||
): | ||
response.delete_cookie( | ||
key=settings.SESSION_METADATA_COOKIE_NAME, | ||
path=settings.SESSION_COOKIE_PATH, | ||
domain=settings.SESSION_COOKIE_DOMAIN, | ||
samesite=settings.SESSION_COOKIE_SAMESITE, | ||
) | ||
|
||
return response |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters