diff --git a/backend/open_webui/routers/auths.py b/backend/open_webui/routers/auths.py index 16ae0422e8..a07d5ed678 100644 --- a/backend/open_webui/routers/auths.py +++ b/backend/open_webui/routers/auths.py @@ -75,6 +75,7 @@ from open_webui.utils.auth import ( verify_password, ) from open_webui.utils.groups import apply_default_group_assignment +from open_webui.utils.json_codec import JSONCodec from open_webui.utils.misc import parse_duration, validate_email_format from open_webui.utils.rate_limit import RateLimiter from pydantic import BaseModel, StrictStr, field_validator @@ -1463,6 +1464,9 @@ OAUTH_CONFIG_KEYS = { def _format_oauth_form_value(field: str, value): + if field == 'OAUTH_BLOCKED_GROUPS' and isinstance(value, list): + # Preserve commas in group names and regex patterns when the form is saved. + return JSONCodec.dumps(value) if field in OAUTH_COMMA_LIST_FIELDS and isinstance(value, list): return ','.join(str(item) for item in value) return value diff --git a/backend/open_webui/utils/oauth.py b/backend/open_webui/utils/oauth.py index 10dedb1e6c..ca8e3a1d75 100644 --- a/backend/open_webui/utils/oauth.py +++ b/backend/open_webui/utils/oauth.py @@ -351,6 +351,19 @@ def is_in_blocked_groups(group_name: str, groups: list) -> bool: return False +def _parse_blocked_groups(value) -> list[str]: + """Accept JSON arrays, persisted lists, and comma-separated admin input.""" + if isinstance(value, str): + try: + parsed = JSONCodec.loads(value) + except JSONCodec.JSONDecodeError: + parsed = None + value = parsed if isinstance(parsed, list) else [group.strip() for group in value.split(',')] + if not isinstance(value, list): + return [] + return [group for group in value if isinstance(group, str) and group] + + def get_parsed_and_base_url(server_url) -> tuple[urllib.parse.ParseResult, str]: parsed = urllib.parse.urlparse(server_url) base_url = f'{parsed.scheme}://{parsed.netloc}' @@ -1636,11 +1649,7 @@ class OAuthManager: log.debug('Running OAUTH Group management') oauth_claim = auth_config.OAUTH_GROUPS_CLAIM - try: - blocked_groups = JSONCodec.loads(auth_config.OAUTH_BLOCKED_GROUPS) - except Exception as e: - log.exception(f'Error loading OAUTH_BLOCKED_GROUPS: {e}') - blocked_groups = [] + blocked_groups = _parse_blocked_groups(auth_config.OAUTH_BLOCKED_GROUPS) user_oauth_groups = [] # Nested claim search for groups claim