Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion src/uds/core/util/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,8 @@ class GlobalConfig:
type=Config.FieldType.TEXT,
help=_(
"SameSite policy of the session cookie: Lax or Strict. Lax is required for SSO "
"logins (SAML, OAuth2, EntraID) to keep the session after the identity provider redirects back"
"logins (SAML, OAuth2, EntraID) to keep the session after the identity provider redirects back. "
"Changes apply after restarting uds and udsweb on every server"
),
group=Config.GroupType.HARDENING,
)
Expand Down
6 changes: 3 additions & 3 deletions src/uds/core/util/session_samesite.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@


def configured_value() -> str:
# force=True: the config cache is per process and this runs only when a session cookie is written,
# so reading the database here keeps every worker on the value saved from the web.
value = GlobalConfig.SESSION_COOKIE_SAMESITE.as_str(force=True)
# Cached per process like the rest of GlobalConfig: a change saved from the web applies to the
# worker that saved it at once, and to the others after restarting uds and udsweb.
value = GlobalConfig.SESSION_COOKIE_SAMESITE.as_str()
if value in SESSION_COOKIE_SAMESITE_VALUES:
return value
logger.warning(
Expand Down
11 changes: 11 additions & 0 deletions tests/core/util/test_session_samesite.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,17 @@ def test_value_saved_from_web_is_applied_to_session_cookie(self) -> None:
self.assertEqual(settings.SESSION_COOKIE_SAMESITE, value)
self.assertEqual(self.session_cookie_samesite(), value)

def test_value_is_cached_until_restart(self) -> None:
GlobalConfig.SESSION_COOKIE_SAMESITE.set("Strict")
DBConfig.objects.filter(
section=GlobalConfig.SESSION_COOKIE_SAMESITE.section(),
key=GlobalConfig.SESSION_COOKIE_SAMESITE.key(),
).update(value="Lax")

self.assertEqual(settings.SESSION_COOKIE_SAMESITE, "Strict")
GlobalConfig.SESSION_COOKIE_SAMESITE.get(force=True)
self.assertEqual(settings.SESSION_COOKIE_SAMESITE, "Lax")

def test_invalid_value_falls_back_to_default(self) -> None:
GlobalConfig.SESSION_COOKIE_SAMESITE.set("None")

Expand Down
Loading