@@ -127,6 +127,8 @@ class Session(dict):
127
127
to keep backward compatibility with sessions generated before 1.8.0
128
128
set this to 48.
129
129
:param crypto_type: encryption module to use
130
+ :param samesite: SameSite value for the cookie -- should be either 'Lax',
131
+ 'Strict', or None.
130
132
"""
131
133
def __init__ (self , request , id = None , invalidate_corrupt = False ,
132
134
use_cookies = True , type = None , data_dir = None ,
@@ -135,7 +137,7 @@ def __init__(self, request, id=None, invalidate_corrupt=False,
135
137
data_serializer = 'pickle' , secret = None ,
136
138
secure = False , namespace_class = None , httponly = False ,
137
139
encrypt_key = None , validate_key = None , encrypt_nonce_bits = DEFAULT_NONCE_BITS ,
138
- crypto_type = 'default' ,
140
+ crypto_type = 'default' , samesite = 'Lax' ,
139
141
** namespace_args ):
140
142
if not type :
141
143
if data_dir :
@@ -178,6 +180,7 @@ def __init__(self, request, id=None, invalidate_corrupt=False,
178
180
self .secret = secret
179
181
self .secure = secure
180
182
self .httponly = httponly
183
+ self .samesite = samesite
181
184
self .encrypt_key = encrypt_key
182
185
self .validate_key = validate_key
183
186
self .encrypt_nonce_size = get_nonce_size (encrypt_nonce_bits )
@@ -246,6 +249,8 @@ def _set_cookie_values(self, expires=None):
246
249
self .cookie [self .key ]['domain' ] = self ._domain
247
250
if self .secure :
248
251
self .cookie [self .key ]['secure' ] = True
252
+ if self .samesite :
253
+ self .cookie [self .key ]['samesite' ] = self .samesite
249
254
self ._set_cookie_http_only ()
250
255
self .cookie [self .key ]['path' ] = self ._path
251
256
@@ -556,13 +561,15 @@ class CookieSession(Session):
556
561
otherwise invalid data will cause an exception.
557
562
:type invalidate_corrupt: bool
558
563
:param crypto_type: The crypto module to use.
564
+ :param samesite: SameSite value for the cookie -- should be either 'Lax',
565
+ 'Strict', or None.
559
566
"""
560
567
def __init__ (self , request , key = 'beaker.session.id' , timeout = None ,
561
568
save_accessed_time = True , cookie_expires = True , cookie_domain = None ,
562
569
cookie_path = '/' , encrypt_key = None , validate_key = None , secure = False ,
563
570
httponly = False , data_serializer = 'pickle' ,
564
571
encrypt_nonce_bits = DEFAULT_NONCE_BITS , invalidate_corrupt = False ,
565
- crypto_type = 'default' ,
572
+ crypto_type = 'default' , samesite = 'Lax' ,
566
573
** kwargs ):
567
574
568
575
self .crypto_module = get_crypto_module (crypto_type )
@@ -582,6 +589,7 @@ def __init__(self, request, key='beaker.session.id', timeout=None,
582
589
self .request ['set_cookie' ] = False
583
590
self .secure = secure
584
591
self .httponly = httponly
592
+ self .samesite = samesite
585
593
self ._domain = cookie_domain
586
594
self ._path = cookie_path
587
595
self .invalidate_corrupt = invalidate_corrupt
0 commit comments