Open-source AI teammates in Slack, Teams, Discord, Telegram and Mattermost. Self-host it, with any agent harness and any model.
Python agent-orchestrationaiai-agentschatopsdiscordlangchainmcpmicrosoft-teamsmulti-agentopen-sourceopenaiself-hostedslack
fix(gateway): admin-gate every collaboration bridge write (CHOO-1784)
Louis Amaudruz98654cdaa12a
diff --git a/core/switch_core/gateway/collaborations.py b/core/switch_core/gateway/collaborations.pyindex 145383efa..d7e4ea6ac 100644--- a/core/switch_core/gateway/collaborations.py+++ b/core/switch_core/gateway/collaborations.py@@ -158,7 +158,9 @@ async def update_bridge(session: Annotated[AsyncSession, Depends(get_session)],bridge_store: Annotated[CollaborationBridgeStore, Depends(get_bridge_store)],room_store: Annotated[RoomStore, Depends(get_room_store)],- _user: Annotated[User, Depends(get_current_user)],+ # Admin-only for the same reason as registering one: a bridge is an unowned,+ # workspace-wide integration, so there is no owner to scope mutation to.+ _user: Annotated[User, Depends(require_admin)],) -> BridgeDetail:bridge = await bridge_store.get(session, bridge_id)if bridge is None:@@ -215,7 +217,9 @@ async def delete_bridge(collab_lifecycle: Annotated[CollaborationBridgeLifecycleService, Depends(get_collab_lifecycle)],- _user: Annotated[User, Depends(get_current_user)],+ # Admin-only: deleting a bridge cascades into deleting every room on it, so+ # this is the most destructive operation on the router.+ _user: Annotated[User, Depends(require_admin)],) -> dict[str, bool]:bridge = await bridge_store.get(session, bridge_id)if bridge is None:diff --git a/core/tests/switch_core/gateway/test_collaborations_authz.py b/core/tests/switch_core/gateway/test_collaborations_authz.pyindex 37f6388fb..f5605161d 100644--- a/core/tests/switch_core/gateway/test_collaborations_authz.py+++ b/core/tests/switch_core/gateway/test_collaborations_authz.py@@ -66,17 +66,34 @@ def test_collab_api_module_is_gone() -> None:# ── 2. gateway collaboration routes are authorized ───────────────────────────+WRITE_METHODS = {"POST", "PATCH", "PUT", "DELETE"}++def test_bridge_write_routes_require_admin() -> None:- """create + set-default (the state-changing admin actions) must be gated on- require_admin — a bridge is an unowned, workspace-wide integration holding- platform secrets."""- admin_gated = {- (frozenset(route.methods), route.path)+ """EVERY state-changing route must be gated on require_admin — a bridge is an+ unowned, workspace-wide integration holding platform secrets, so there is no+ owner to scope mutation to.++ Derived from the router rather than a hand-listed set: a new write route that+ forgets the gate fails here instead of shipping open.+ """+ unguarded = sorted(+ f"{sorted(route.methods & WRITE_METHODS)} {route.path}"for route in router.routes- if require_admin in _dependency_calls(route.dependant)- }- assert (frozenset({"POST"}), "") in admin_gated # create- assert (frozenset({"POST"}), "/{bridge_id}/default") in admin_gated # set-default+ if route.methods & WRITE_METHODS+ and require_admin not in _dependency_calls(route.dependant)+ )+ assert not unguarded, f"collaboration write routes missing require_admin: {unguarded}"+++def test_known_bridge_write_routes_are_present() -> None:+ """Guard against the check above passing vacuously if a route is renamed or+ dropped: the four writes we know about must still exist."""+ routes = {(frozenset(r.methods) & WRITE_METHODS, r.path) for r in router.routes}+ assert (frozenset({"POST"}), "") in routes # create+ assert (frozenset({"POST"}), "/{bridge_id}/default") in routes # set-default+ assert (frozenset({"PATCH"}), "/{bridge_id}") in routes # update+ assert (frozenset({"DELETE"}), "/{bridge_id}") in routes # deletedef test_every_collaboration_route_requires_authentication() -> None: