diff --git a/src/uds/core/util/config.py b/src/uds/core/util/config.py index a3bb162f1..e2cc9037b 100644 --- a/src/uds/core/util/config.py +++ b/src/uds/core/util/config.py @@ -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, ) diff --git a/src/uds/core/util/session_samesite.py b/src/uds/core/util/session_samesite.py index c7426ad2f..0f90570d6 100644 --- a/src/uds/core/util/session_samesite.py +++ b/src/uds/core/util/session_samesite.py @@ -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( diff --git a/tests/core/util/test_session_samesite.py b/tests/core/util/test_session_samesite.py index 732e7325d..be3a0833f 100644 --- a/tests/core/util/test_session_samesite.py +++ b/tests/core/util/test_session_samesite.py @@ -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")