fix: add knowledge_id access check in search_knowledge_files (BOLA) (#25113)
When called without attached model knowledge and given a caller-supplied knowledge_id, search_knowledge_files passed it straight to Knowledges.search_files_by_id, which does not enforce ownership on knowledge_id. An authenticated user who happened to know a target UUID could enumerate file metadata (filename, file id, KB id, KB name, updated_at) from any knowledge base, bypassing the AccessGrants permission model. Mirror the same admin/owner/AccessGrants check the attached-KB branch already uses, matching the sibling query_knowledge_files function. Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.7
parent
48ea043f82
commit
9f20687680
@@ -1713,6 +1713,21 @@ async def search_knowledge_files(
|
||||
|
||||
# No attached knowledge - search all accessible KBs
|
||||
if knowledge_id:
|
||||
# search_files_by_id does not enforce knowledge_id ownership; mirror the attached-KB check above.
|
||||
knowledge = await Knowledges.get_knowledge_by_id(knowledge_id)
|
||||
if not knowledge or not (
|
||||
user_role == 'admin'
|
||||
or knowledge.user_id == user_id
|
||||
or await AccessGrants.has_access(
|
||||
user_id=user_id,
|
||||
resource_type='knowledge',
|
||||
resource_id=knowledge.id,
|
||||
permission='read',
|
||||
user_group_ids=set(user_group_ids),
|
||||
)
|
||||
):
|
||||
return json.dumps({'error': f'Access denied to knowledge base {knowledge_id}'})
|
||||
|
||||
result = await Knowledges.search_files_by_id(
|
||||
knowledge_id=knowledge_id,
|
||||
user_id=user_id,
|
||||
|
||||
Reference in New Issue
Block a user