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
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
.. versionchanged:: 3.8
Added support for the :attr:`samesite` attribute.
+ .. versionchanged:: 3.14
+ Added support for the :attr:`partitioned` attribute.
+
.. attribute:: Morsel.value
"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
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: