From 645c9d59004e5710f1e040997be4aa57ddadde29 Mon Sep 17 00:00:00 2001 From: Raphael Michel Date: Thu, 25 Jan 2024 09:46:04 +0100 Subject: [PATCH] Add "Partitioned" flag to our cookies (#3830) --- src/pretix/helpers/cookies.py | 2 ++ src/pretix/helpers/monkeypatching.py | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/src/pretix/helpers/cookies.py b/src/pretix/helpers/cookies.py index cbf0708d32..ee73465942 100644 --- a/src/pretix/helpers/cookies.py +++ b/src/pretix/helpers/cookies.py @@ -44,6 +44,8 @@ def set_cookie_without_samesite(request, response, key, *args, **kwargs): # This will only work on secure cookies as well # https://www.chromestatus.com/feature/5633521622188032 response.cookies[key]['secure'] = is_secure + # CHIPS + response.cookies[key]['Partitioned'] = True # Based on https://www.chromium.org/updates/same-site/incompatible-clients diff --git a/src/pretix/helpers/monkeypatching.py b/src/pretix/helpers/monkeypatching.py index a259bde4a5..b56e9c7c61 100644 --- a/src/pretix/helpers/monkeypatching.py +++ b/src/pretix/helpers/monkeypatching.py @@ -21,6 +21,7 @@ # import types from datetime import datetime +from http import cookies from PIL import Image from requests.adapters import HTTPAdapter @@ -88,7 +89,14 @@ def monkeypatch_requests_timeout(): HTTPAdapter.send = httpadapter_send +def monkeypatch_cookie_morsel(): + # See https://code.djangoproject.com/ticket/34613 + cookies.Morsel._flags.add("partitioned") + cookies.Morsel._reserved.setdefault("partitioned", "Partitioned") + + def monkeypatch_all_at_ready(): monkeypatch_vobject_performance() monkeypatch_pillow_safer() monkeypatch_requests_timeout() + monkeypatch_cookie_morsel()