Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

fix(slack): require automations:CUD to list Slack channels (#19208)

Tobias Wochingerdab6c47bb304
diff --git a/web/src/__tests__/server/slack-integration.servertest.ts b/web/src/__tests__/server/slack-integration.servertest.ts
index cd1b120e25..8255f065c4 100644
--- a/web/src/__tests__/server/slack-integration.servertest.ts
+++ b/web/src/__tests__/server/slack-integration.servertest.ts
@@ -1,7 +1,7 @@
import { testFeatureFlags } from "@/src/__tests__/fixtures/feature-flags";
import type * as SharedServer from "@langfuse/shared/src/server";
import type { Mock } from "vitest";
-import { prisma } from "@langfuse/shared/src/db";
+import { prisma, type Role } from "@langfuse/shared/src/db";
import type { Session } from "next-auth";
import { encrypt } from "@langfuse/shared/encryption";
import { createInnerTRPCContext } from "@/src/server/api/trpc";
@@ -76,7 +76,10 @@ const createIntegration = (
},
});
-const prepare = async () => {
+const prepare = async ({
+ projectRole = "ADMIN",
+ admin = true,
+}: { projectRole?: Role; admin?: boolean } = {}) => {
const { project, org } = await createOrgProjectAndApiKey();
const session: Session = {
@@ -98,7 +101,7 @@ const prepare = async () => {
projects: [
{
id: project.id,
- role: "ADMIN",
+ role: projectRole,
retentionDays: 30,
deletedAt: null,
name: project.name,
@@ -110,7 +113,7 @@ const prepare = async () => {
},
],
featureFlags: testFeatureFlags(),
- admin: true,
+ admin,
},
environment: {
enableExperimentalFeatures: false,
@@ -325,6 +328,23 @@ describe("Slack Integration", () => {
expect(JSON.stringify(asOtherUser)).not.toContain("private");
});
+ it.each(["MEMBER", "VIEWER"] as const)(
+ "should reject %s, who can read automations but not manage them",
+ async (projectRole) => {
+ const { caller, project } = await prepare({
+ projectRole,
+ admin: false,
+ });
+ await createIntegration(project.id, null);
+ mockSlackService.getChannels.mockClear();
+
+ await expect(
+ caller.slack.getChannels({ projectId: project.id }),
+ ).rejects.toMatchObject({ code: "FORBIDDEN" });
+ expect(mockSlackService.getChannels).not.toHaveBeenCalled();
+ },
+ );
+
it("should throw NOT_FOUND for missing integration", async () => {
const { caller, project } = await prepare();
diff --git a/web/src/features/slack/components/ChannelSelector.tsx b/web/src/features/slack/components/ChannelSelector.tsx
index 8de8ad322b..38404c010f 100644
--- a/web/src/features/slack/components/ChannelSelector.tsx
+++ b/web/src/features/slack/components/ChannelSelector.tsx
@@ -2,6 +2,7 @@ import React, { useState, useMemo, useEffect } from "react";
import { api, reportNonTrpcError } from "@/src/utils/api";
import { env } from "@/src/env.mjs";
import { type SlackChannel } from "@langfuse/shared/src/server";
+import { useHasProjectAccess } from "@/src/features/rbac";
import {
ChannelSelectorView,
type ChannelSelectorViewProps,
@@ -33,8 +34,14 @@ export const ChannelSelector: React.FC<ChannelSelectorProps> = ({
...viewProps
}) => {
const [isRefreshing, setIsRefreshing] = useState(false);
+ // Read-only roles still see the saved channel via `selectedChannel`, but
+ // may not enumerate every channel the bot can see.
+ const canListChannels = useHasProjectAccess({
+ projectId,
+ scope: "automations:CUD",
+ });
const { channelsData, isLoadingChannels, error, refetchChannels } =
- useSlackChannels(projectId);
+ useSlackChannels(projectId, canListChannels);
const handleRefresh = async () => {
setIsRefreshing(true);
@@ -56,6 +63,7 @@ export const ChannelSelector: React.FC<ChannelSelectorProps> = ({
return (
<ChannelSelectorView
{...viewProps}
+ disabled={viewProps.disabled || !canListChannels}
channelsData={channelsData}
isLoading={isLoadingChannels}
hasError={!!error}
@@ -66,7 +74,7 @@ export const ChannelSelector: React.FC<ChannelSelectorProps> = ({
);
};
-const useSlackChannels = (projectId: string) => {
+const useSlackChannels = (projectId: string, enabled: boolean) => {
const {
data: channelsPages,
isLoading,
@@ -79,7 +87,7 @@ const useSlackChannels = (projectId: string) => {
} = api.slack.getChannels.useInfiniteQuery(
{ projectId },
{
- enabled: !!projectId,
+ enabled: !!projectId && enabled,
getNextPageParam: (lastPage, allPages) =>
allPages.length >= MAX_SLACK_CHANNEL_PAGES
? undefined
diff --git a/web/src/features/slack/server/router.ts b/web/src/features/slack/server/router.ts
index 55eba78a9b..f751b35905 100644
--- a/web/src/features/slack/server/router.ts
+++ b/web/src/features/slack/server/router.ts
@@ -100,7 +100,7 @@ export const slackRouter = createTRPCRouter({
throwIfNoProjectAccess({
session: ctx.session,
projectId: input.projectId,
- scope: "automations:read",
+ scope: "automations:CUD",
});
const integration = await ctx.prisma.slackIntegration.findUnique({