Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
5901f2e
Add support for 'partitioned' attribute in http.cookies
Dec 4, 2023
a6fe17a
Merge branch 'main' into add-cookies-partitioned-support
giles-v Dec 4, 2023
9175076
📜🤖 Added by blurb_it.
blurb-it[bot] Dec 4, 2023
f20ba61
Fix invalid test name function
Dec 4, 2023
20ac30d
Merge branch 'main' into add-cookies-partitioned-support
gpshead Feb 14, 2024
1482ed7
Merge branch 'main' into add-cookies-partitioned-support
gpshead Feb 14, 2024
80df6e7
Wordsmith the docs and include a link to the spec.
gpshead Feb 14, 2024
21cf60e
Style: Don't retain unusual hand spacing.
gpshead Feb 14, 2024
b1f7cbd
News ReST improvements.
gpshead Feb 14, 2024
f6391d6
Add support for 'partitioned' attribute in http.cookies
Dec 4, 2023
14d9a5c
📜🤖 Added by blurb_it.
blurb-it[bot] Dec 4, 2023
e622cda
Fix invalid test name function
Dec 4, 2023
1949596
Wordsmith the docs and include a link to the spec.
gpshead Feb 14, 2024
9f3c9b0
Style: Don't retain unusual hand spacing.
gpshead Feb 14, 2024
f03bdd9
News ReST improvements.
gpshead Feb 14, 2024
097fc45
Remove Path=/ mandatory requirement from the docs
Sep 9, 2024
de432da
Pull changes
Sep 9, 2024
c564125
Merge branch 'main' into add-cookies-partitioned-support
giles-v Sep 9, 2024
4fdecb5
Move morsel docs version to 3.1.4, and revert spacing changes
Dec 10, 2024
7dc5110
Merge upstream/main
Dec 10, 2024
bb95c15
Merge branch 'main' into add-cookies-partitioned-support
giles-v Jan 22, 2025
e9363fb
Merge branch 'main' into add-cookies-partitioned-support
giles-v Jan 24, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions Doc/library/http.cookies.rst
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ Morsel Objects
version
httponly
samesite
partitioned

The attribute :attr:`httponly` specifies that the cookie is only transferred
in HTTP requests, and is not accessible through JavaScript. This is intended
Expand All @@ -151,6 +152,19 @@ Morsel Objects
send the cookie along with cross-site requests. This helps to mitigate CSRF
attacks. Valid values for this attribute are "Strict" and "Lax".

The attribute :attr:`partitioned` indicates to user agents that these
cross-site cookies *should* only be available in the same top-level context
that the cookie was first set in. For this to be accepted by the user agent,
you **must** also set ``Secure``.

In addition, it is recommended to use the ``__Host`` prefix when setting
partitioned cookies to make them bound to the hostname and not the
registrable domain. Read
`CHIPS (Cookies Having Independent Partitioned State)`_
for full details and examples.

.. _CHIPS (Cookies Having Independent Partitioned State): https://github.com/privacycg/CHIPS/blob/main/README.md

The keys are case-insensitive and their default value is ``''``.

.. versionchanged:: 3.5
Expand All @@ -165,6 +179,9 @@ Morsel Objects
.. versionchanged:: 3.8
Added support for the :attr:`samesite` attribute.

.. versionchanged:: 3.14
Added support for the :attr:`partitioned` attribute.


.. attribute:: Morsel.value

Expand Down
3 changes: 2 additions & 1 deletion Lib/http/cookies.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,11 +264,12 @@ class Morsel(dict):
"httponly" : "HttpOnly",
"version" : "Version",
"samesite" : "SameSite",
"partitioned": "Partitioned",
}

_reserved_defaults = dict.fromkeys(_reserved, "")

_flags = {'secure', 'httponly'}
_flags = {'secure', 'httponly', 'partitioned'}

def __init__(self):
# Set defaults
Expand Down
8 changes: 8 additions & 0 deletions Lib/test/test_http_cookies.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,14 @@ def test_set_secure_httponly_attrs(self):
self.assertEqual(C.output(),
'Set-Cookie: Customer="WILE_E_COYOTE"; HttpOnly; Secure')

def test_set_secure_httponly_partitioned_attrs(self):
C = cookies.SimpleCookie('Customer="WILE_E_COYOTE"')
C['Customer']['secure'] = True
C['Customer']['httponly'] = True
C['Customer']['partitioned'] = True
self.assertEqual(C.output(),
'Set-Cookie: Customer="WILE_E_COYOTE"; HttpOnly; Partitioned; Secure')

def test_samesite_attrs(self):
samesite_values = ['Strict', 'Lax', 'strict', 'lax']
for val in samesite_values:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added support for the ``Partitioned`` cookie flag in :mod:`http.cookies`.
Loading