Skip to content

Commit 9417607

Browse files
committed
Support partitioned cookies
This follows Flask's implementation and allows for cookies to be marked as partitioned. This in turn will allow a third party cookie to work on the origin the top-level site it is set on and not others. Without partitioned the browser may (is likely) to block the cookie outright.
1 parent ba0e497 commit 9417607

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/quart/app.py

+1
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ class Quart(App):
263263
"SESSION_COOKIE_DOMAIN": None,
264264
"SESSION_COOKIE_HTTPONLY": True,
265265
"SESSION_COOKIE_NAME": "session",
266+
"SESSION_COOKIE_PARTITIONED": False,
266267
"SESSION_COOKIE_PATH": None,
267268
"SESSION_COOKIE_SAMESITE": None,
268269
"SESSION_COOKIE_SECURE": False,

src/quart/sessions.py

+7
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ def get_cookie_domain(self, app: Quart) -> str | None:
5555
rv = app.config["SESSION_COOKIE_DOMAIN"]
5656
return rv if rv else None
5757

58+
def get_cookie_partitioned(self, app: Quart) -> bool:
59+
"""Helper method to return the Cookie partitioned setting for the App."""
60+
return app.config["SESSION_COOKIE_PARTITIONED"]
61+
5862
def get_cookie_path(self, app: Quart) -> str:
5963
"""Helper method to return the Cookie path for the App."""
6064
return app.config["SESSION_COOKIE_PATH"] or app.config["APPLICATION_ROOT"]
@@ -195,6 +199,7 @@ async def save_session(
195199

196200
name = self.get_cookie_name(app)
197201
domain = self.get_cookie_domain(app)
202+
partitioned = self.get_cookie_partitioned(app)
198203
path = self.get_cookie_path(app)
199204
secure = self.get_cookie_secure(app)
200205
samesite = self.get_cookie_samesite(app)
@@ -211,6 +216,7 @@ async def save_session(
211216
response.delete_cookie(
212217
name,
213218
domain=domain,
219+
partitioned=partitioned,
214220
path=path,
215221
secure=secure,
216222
samesite=samesite,
@@ -231,6 +237,7 @@ async def save_session(
231237
expires=expires,
232238
httponly=httponly,
233239
domain=domain,
240+
partitioned=partitioned,
234241
path=path,
235242
secure=secure,
236243
samesite=samesite,

0 commit comments

Comments
 (0)