mirror of
https://github.com/aljazceru/CTFd.git
synced 2025-12-18 06:24:23 +01:00
Default SameSite session cookie setting to Lax (#824)
This commit is contained in:
@@ -93,6 +93,7 @@ class Config(object):
|
||||
solely on IP addresses unless you know what you are doing.
|
||||
'''
|
||||
SESSION_COOKIE_HTTPONLY = (not os.getenv("SESSION_COOKIE_HTTPONLY")) # Defaults True
|
||||
SESSION_COOKIE_SAMESITE = os.getenv("SESSION_COOKIE_SAMESITE") or 'Lax'
|
||||
PERMANENT_SESSION_LIFETIME = int(os.getenv("PERMANENT_SESSION_LIFETIME") or 604800) # 7 days in seconds
|
||||
TRUSTED_PROXIES = [
|
||||
r'^127\.0\.0\.1$',
|
||||
|
||||
@@ -88,6 +88,7 @@ class CachingSessionInterface(SessionInterface):
|
||||
httponly = self.get_cookie_httponly(app)
|
||||
secure = self.get_cookie_secure(app)
|
||||
expires = self.get_expiration_time(app, session)
|
||||
samesite = self.get_cookie_samesite(app)
|
||||
val = self.serializer.dumps(dict(session))
|
||||
|
||||
if session.sid is None:
|
||||
@@ -102,5 +103,6 @@ class CachingSessionInterface(SessionInterface):
|
||||
httponly=httponly,
|
||||
domain=domain,
|
||||
path=path,
|
||||
secure=secure
|
||||
secure=secure,
|
||||
samesite=samesite
|
||||
)
|
||||
|
||||
21
tests/utils/test_sessions.py
Normal file
21
tests/utils/test_sessions.py
Normal file
@@ -0,0 +1,21 @@
|
||||
from tests.helpers import *
|
||||
|
||||
|
||||
def test_sessions_set_httponly():
|
||||
app = create_ctfd()
|
||||
with app.app_context():
|
||||
with app.test_client() as client:
|
||||
r = client.get('/')
|
||||
cookie = dict(r.headers)['Set-Cookie']
|
||||
assert 'HttpOnly;' in cookie
|
||||
destroy_ctfd(app)
|
||||
|
||||
|
||||
def test_sessions_set_samesite():
|
||||
app = create_ctfd()
|
||||
with app.app_context():
|
||||
with app.test_client() as client:
|
||||
r = client.get('/')
|
||||
cookie = dict(r.headers)['Set-Cookie']
|
||||
assert 'SameSite=' in cookie
|
||||
destroy_ctfd(app)
|
||||
Reference in New Issue
Block a user