diff --git a/backend/open_webui/utils/access_control/__init__.py b/backend/open_webui/utils/access_control/__init__.py index d0345ccdd5..975008b4c1 100644 --- a/backend/open_webui/utils/access_control/__init__.py +++ b/backend/open_webui/utils/access_control/__init__.py @@ -276,6 +276,7 @@ async def has_base_model_access( user_id: str, model_info, *, + user_role: str | None = None, user_group_ids: set[str] | None = None, db=None, ) -> bool: @@ -283,9 +284,11 @@ async def has_base_model_access( Walk the ``base_model_id`` chain and verify the caller has read access at every hop. - Returns ``True`` when access is granted (or the chain ends at a raw - provider model that has no per-model ACL). Returns ``False`` the - moment a registered base model denies access. + A base model without a ``model`` table row is admin-only, matching how + unregistered models are treated for direct use (``get_filtered_models`` + hides them from non-admins and ``check_model_access`` rejects them), so + a shared preset cannot be used to reach a base model the caller could + not use directly. Returns ``False`` the moment any hop denies access. """ from open_webui.models.access_grants import AccessGrants from open_webui.models.models import Models @@ -296,7 +299,7 @@ async def has_base_model_access( seen.add(base_model_id) base_model_info = await Models.get_model_by_id(base_model_id, db=db) if base_model_info is None: - break # Raw provider model — no per-model ACL + return user_role == 'admin' if not ( user_id == base_model_info.user_id or await AccessGrants.has_access( @@ -355,7 +358,9 @@ async def check_model_access( raise HTTPException(status_code=403, detail='Model not found') # Enforce access on chained base models - if not await has_base_model_access(user.id, model_info, user_group_ids=user_group_ids): + if not await has_base_model_access( + user.id, model_info, user_role=user.role, user_group_ids=user_group_ids + ): raise HTTPException(status_code=403, detail='Model not found') else: if user.role != 'admin': diff --git a/backend/open_webui/utils/models.py b/backend/open_webui/utils/models.py index ddc59180fd..a5b2261b14 100644 --- a/backend/open_webui/utils/models.py +++ b/backend/open_webui/utils/models.py @@ -456,7 +456,7 @@ async def check_model_access(user, model, db=None): raise Exception('Model not found') # Enforce access on chained base models - if not await has_base_model_access(user.id, model_info, db=db): + if not await has_base_model_access(user.id, model_info, user_role=user.role, db=db): raise Exception('Model not found')