Skip to content

Commit f44b7a0

Browse files
committed
refac
1 parent 2c7acb9 commit f44b7a0

1 file changed

Lines changed: 19 additions & 6 deletions

File tree

backend/open_webui/retrieval/utils.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -939,19 +939,24 @@ async def filter_accessible_collections(
939939
) -> set[str]:
940940
"""
941941
Return only the collection names the user is allowed to access.
942-
Admins bypass all checks. For non-admins:
942+
Admins bypass all checks. For non-admins the policy is:
943+
943944
- file-* → validated via has_access_to_file
944945
- user-memory-* → must match user's own memory collection
945-
- knowledge-bases → always denied (meta-collection)
946-
- known KB ids → validated via Knowledges.check_access_by_user_id
947-
- everything else → allowed (ephemeral collections like web-search-*)
946+
- web-search-* → ephemeral per-query collections, always allowed
947+
- knowledge-bases → always denied (system meta-collection)
948+
- everything else → if the name matches a knowledge base, validated
949+
via Knowledges.check_access_by_user_id; if no
950+
such KB exists, the name is treated as an
951+
ephemeral/legacy collection and allowed
948952
"""
949953
if user.role == 'admin':
950954
return collection_names
951955

952956
validated = set()
953957
for name in collection_names:
954958
if name == 'knowledge-bases':
959+
# System meta-collection — never exposed to non-admins.
955960
continue
956961
elif name.startswith('file-'):
957962
file_id = name[len('file-'):]
@@ -960,12 +965,20 @@ async def filter_accessible_collections(
960965
elif name.startswith('user-memory-'):
961966
if name == f'user-memory-{user.id}':
962967
validated.add(name)
968+
elif name.startswith('web-search-'):
969+
# Ephemeral collections created by process_web_search — safe
970+
# to allow because they contain only transient web-search
971+
# results scoped to the requesting user's session.
972+
validated.add(name)
963973
else:
964-
# May be a knowledge-base ID or an ephemeral collection
974+
# May be a knowledge-base ID or a legacy/ephemeral collection.
975+
# If it IS a KB, enforce access control. If no such KB
976+
# exists, treat it as a non-sensitive collection (e.g. legacy
977+
# model knowledge, process_text SHA256 collections) and allow.
965978
if await Knowledges.check_access_by_user_id(name, user.id, permission=access_type):
966979
validated.add(name)
967980
elif not await Knowledges.get_knowledge_by_id(name):
968-
# Not a KB at all — ephemeral collection (e.g. web-search-*), allow
981+
# Not a KB at all — legacy/ephemeral collection, allow
969982
validated.add(name)
970983
return validated
971984

0 commit comments

Comments
 (0)