fix(workstation): hide tools the requester lacks view_tool on (IKABQ0) - #2354
Open
yaojin3616 wants to merge 1 commit into
Open
fix(workstation): hide tools the requester lacks view_tool on (IKABQ0)#2354yaojin3616 wants to merge 1 commit into
yaojin3616 wants to merge 1 commit into
Conversation
The end-user workspace chat toolbar (GET /api/v1/workstation/config) was returning every tool the admin had configured for daily chat, with no intersection against the caller's view_tool / use_tool permission. Any logged-in end user could therefore see the full set of API and MCP tools the admin had pinned for the daily-chat agent, regardless of whether they had been granted access. This was a leak of the admin workbench surface into the end-user chat surface. Mirror the platform tool list path (tool.domain.services.tool): pipe the projected tool list through ToolPermissionService.filter_tool_ids_by_permission_async(user_id, ids, "view_tool") before returning. Wire login_user through aget_config / get_daily_chat_config / get_daily_chat_config_with_meta / get_linsight_config / get_linsight_config_with_meta and update the endpoint handlers (config, apps) and the chat service to pass it. The filter is fail-closed on permission-probe errors (no leak), bypassed for admins (config page still echoes every configured tool), and a no-op when login_user is None (legacy/test paths keep prior behaviour). Regression coverage in test/workstation/test_workstation_tool_permission_filter.py covers the non-admin-without-permission, admin-bypass, no-login-user, fail-closed, empty-list, and missing-id cases. Closes IKABQ0.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The end-user workspace chat toolbar (
GET /api/v1/workstation/config) wasreturning every tool the admin had configured for daily chat, with no
intersection against the caller's
view_tool/use_toolpermission. Anylogged-in end user could therefore see the full set of API and MCP tools
the admin had pinned for the daily-chat agent, regardless of whether
they had been granted access. This was a leak of the admin workbench
surface into the end-user chat surface.
Root cause
WorkStationService.aget_config()/get_daily_chat_config()/get_linsight_config()returned theadmin-configured
WorkstationConfig.toolslist verbatim, with noper-user permission intersection. The platform tool list path
(
tool.domain.services.tool.ToolServices.get_tool_list) already doesthis via
ToolPermissionService.filter_tool_ids_by_permission_asyncwhen listing tools in the admin UI; the workstation path did not.
Fix
WorkStationService._afilter_tools_by_view_permission, which pipesthe projected tool list through
ToolPermissionService.filter_tool_ids_by_permission_async(user_id, ids, "view_tool")before returning.login_userthrough the public service methods(
aget_config,get_daily_chat_config,get_daily_chat_config_with_meta,get_linsight_config,get_linsight_config_with_meta) and their internal projectionhelpers. Update endpoint handlers (
/config,/config/daily,/config/linsight,/app/recommended) and the chat service to passthe caller's
login_user.for admins (config page still echoes every configured tool), and a
no-op when
login_user is None(legacy/test paths keep priorbehaviour).
Files
src/backend/bisheng/workstation/domain/services/workstation_service.py— add helper, propagate
login_user, apply filter in both inheritedand non-inherited branches.
src/backend/bisheng/workstation/api/endpoints/config.py— passlogin_userto the three public service methods.src/backend/bisheng/workstation/api/endpoints/apps.py— passlogin_usertoaget_config.src/backend/bisheng/workstation/domain/services/chat_service.py—pass
login_userto the twoaget_configcallers.src/backend/test/workstation/test_workstation_tool_permission_filter.py— regression coverage: non-admin-without-permission, admin bypass,
no-login-user, fail-closed, empty list, and missing-id cases.
Test plan
test/workstation/test_workstation_tool_permission_filter.pycoversthe helper's six behavioural branches.
test/workstation/*suite to confirm no regressions(all callers updated, the new
login_userparameter is keyword-onlywith a default of
Noneso mocks that don't pass it still work).view_toolon aconfigured API/MCP tool, open the chat workspace, confirm the tool
no longer appears in the agent tool selector. Re-test as an admin
and confirm the tool is still visible.
Risk
Low. The change is additive (a new
login_userkeyword argument onthe public methods) and the filter is bypassed when no user is passed
so existing tests / legacy call paths that don't yet pass
login_userkeep their prior behaviour.
Closes IKABQ0.