@@ -257,6 +257,47 @@ async def filter_allowed_access_grants(
257257 return access_grants
258258
259259
260+ async def has_base_model_access (
261+ user_id : str ,
262+ model_info ,
263+ * ,
264+ user_group_ids : set [str ] | None = None ,
265+ db = None ,
266+ ) -> bool :
267+ """
268+ Walk the ``base_model_id`` chain and verify the caller has read access
269+ at every hop.
270+
271+ Returns ``True`` when access is granted (or the chain ends at a raw
272+ provider model that has no per-model ACL). Returns ``False`` the
273+ moment a registered base model denies access.
274+ """
275+ from open_webui .models .models import Models
276+ from open_webui .models .access_grants import AccessGrants
277+
278+ base_model_id = getattr (model_info , 'base_model_id' , None )
279+ seen = {model_info .id }
280+ while base_model_id and base_model_id not in seen :
281+ seen .add (base_model_id )
282+ base_model_info = await Models .get_model_by_id (base_model_id , db = db )
283+ if base_model_info is None :
284+ break # Raw provider model — no per-model ACL
285+ if not (
286+ user_id == base_model_info .user_id
287+ or await AccessGrants .has_access (
288+ user_id = user_id ,
289+ resource_type = 'model' ,
290+ resource_id = base_model_info .id ,
291+ permission = 'read' ,
292+ user_group_ids = user_group_ids ,
293+ db = db ,
294+ )
295+ ):
296+ return False
297+ base_model_id = getattr (base_model_info , 'base_model_id' , None )
298+ return True
299+
300+
260301async def check_model_access (
261302 user : UserModel ,
262303 model_info ,
@@ -296,6 +337,12 @@ async def check_model_access(
296337 )
297338 ):
298339 raise HTTPException (status_code = 403 , detail = 'Model not found' )
340+
341+ # Enforce access on chained base models
342+ if not await has_base_model_chain_access (
343+ user .id , model_info , user_group_ids = user_group_ids
344+ ):
345+ raise HTTPException (status_code = 403 , detail = 'Model not found' )
299346 else :
300347 if user .role != 'admin' :
301348 raise HTTPException (status_code = 403 , detail = 'Model not found' )
0 commit comments